I'm looking for a working example how connect standard output of spawned external command to a unix socket. So far, I put up following snippet.
require 'socket'
class XkbSocket
def initialize
@sock_cld, @sock_par = UNIXSocket.pair
at_exit {@sock_cld.close; @sock_par.close}
pid = spawn 'xkb-switch -W', @sock_cld => @sock_par
Process.detach pid
rescue Errno::ENOENT
@sock_cld.puts "N/A"
end
end
I am using socket pair, however they are not mapped to some real files so inaccessible for other clients.
I'd like to update above example, so it will create /tmp/mysocket
file for external consumers.
Thanks.