3 # conmux-attach -- attach commands to the console
5 # Attach stand alone commands to a console stream. You can specify
6 # which of the commands file descriptors are connected to which of the
7 # 'steams' in the multiplexor; the console input/output and the user
10 # (C) Copyright IBM Corp. 2004, 2005, 2006
11 # Author: Andy Whitcroft <andyw@uk.ibm.com>
13 # The Console Multiplexor is released under the GNU Public License V2
17 use Getopt
::Long
qw(:config no_auto_abbrev);
19 # Find our internal libraries.
20 use lib
$FindBin::Bin
;
23 my $P = 'conmux-attach';
30 'e|stderr=s' => \
$err,
34 if ($in eq '' && $out eq '' && $err eq '') {
40 print STDERR
"$P: <host:port> <program> ...\n";
43 my ($mux, $app) = @ARGV;
45 $app =~ s@
.*/@@
; $app =~ s@\s
.*$@@
;
46 $app = $bot if ($bot);
49 # Connect to the client channel.
52 my ($mux, $type) = @_;
54 if (!$cache{$mux, $type}) {
55 my $con = Conmux
::connect($mux);
56 my %r = Conmux
::sendCmd
($con, 'CONNECT', {
57 'id' => 'bot:' . $app,
60 die "$P: $mux: connect failed - $r{'status'}\n"
61 if ($r{'status'} ne "OK");
63 $cache{$mux, $type} = $con;
70 my $to = conmux_connect
($mux, $in);
71 open(STDIN
, "<&", $to) ||
72 die "$P: unable to hand off socket to stdin - $!\n";
75 my $to = conmux_connect
($mux, $out);
76 open(STDOUT
, ">&", $to) ||
77 die "$P: unable to hand off socket to stdout - $!\n";
80 my $to = conmux_connect
($mux, $err);
81 open(STDERR
, ">&", $to) ||
82 die "$P: unable to hand off socket to stderr - $!\n";