Sha256: b60f0117b460fff3b58aa1194c09ef7a7a779cfbfa80b163ebb45c33b7a7cf04
Contents?: true
Size: 1.71 KB
Versions: 5
Compression:
Stored size: 1.71 KB
Contents
#!/usr/bin/env ruby =begin ======================================================================= # TORK-REMOTE 1 2012-09-26 18.2.3 ## NAME tork-remote - controls tork(1) programs ## SYNOPSIS `tork-remote` [*OPTION*]... *PROGRAM* ## DESCRIPTION This program reads lines from its stdin and sends them to the given *PROGRAM*, which must already be running in the same working directory as this program. It also prints lines, received in response, from the given *PROGRAM* either to stdout if they are valid single-line JSON arrays or to stderr otherwise. ## OPTIONS `-h`, `--help` Show this help manual. ## EXIT STATUS 1 Could not connect to the *PROGRAM*. 2 Lost connection to the *PROGRAM*. ## SEE ALSO tork(1), tork-driver(1), tork-engine(1), tork-master(1) =end ========================================================================= $0 = File.basename(__FILE__) # for easier identification in ps(1) output require 'binman' BinMan.help require 'socket' require 'shellwords' require 'tork/server' program = ARGV.shift or raise ArgumentError, 'PROGRAM not given' address = Tork::Server.address(program) begin UNIXSocket.open(address) do |socket| # messages to remote from server Thread.new do while input = socket.gets stream = begin JSON.load input STDOUT rescue JSON::ParserError STDERR end stream.puts input stream.flush end warn "#{$0}: lost connection to #{program}" exit 2 end # messages from remote to server while output = STDIN.gets socket.puts output end end rescue Errno::ENOENT => error warn "#{$0}: could not connect to #{program}: #{error}" exit 1 end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
tork-19.7.0 | bin/tork-remote |
tork-19.6.1 | bin/tork-remote |
tork-19.6.0 | bin/tork-remote |
tork-19.5.1 | bin/tork-remote |
tork-19.5.0 | bin/tork-remote |