Sha256: bd2ba9decbe5bd6bd36ce83bd7db8974b17457d00ae2ce1d3f6cecbd03a99d5f

Contents?: true

Size: 1.92 KB

Versions: 10

Compression:

Stored size: 1.92 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 sends single-line JSON messages read from its stdin to the given
*PROGRAM* which is already running in the same working directory as this one.

If lines read from stdin are not single-line JSON messages, then they are
split into an array of words, using the same word-splitting algorithm as
sh(1), before being sent to the *PROGRAM* as a single-line JSON message.

If the *PROGRAM* sends any messages in response, then they are printed to
stdout if they are valid single-line JSON messages 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

10 entries across 10 versions & 1 rubygems

Version Path
tork-19.4.0 bin/tork-remote
tork-19.3.2 bin/tork-remote
tork-19.3.1 bin/tork-remote
tork-19.3.0 bin/tork-remote
tork-19.2.2 bin/tork-remote
tork-19.2.1 bin/tork-remote
tork-19.2.0 bin/tork-remote
tork-19.1.0 bin/tork-remote
tork-19.0.2 bin/tork-remote
tork-19.0.1 bin/tork-remote