X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=jreplclient;fp=jreplclient;h=1ebeaee231c017fdbef888e2cd432c4d447933c7;hb=ff0abfbabde8da2ea39f95faf12f6f38d895d950;hp=0000000000000000000000000000000000000000;hpb=4d5b62fafd82ad425b83da43dee821448f2efd50;p=scpubgit%2FTak.git diff --git a/jreplclient b/jreplclient new file mode 100644 index 0000000..1ebeaee --- /dev/null +++ b/jreplclient @@ -0,0 +1,39 @@ +#!/usr/bin/env perl + +use strictures 1; +use IPC::Open2; +use Term::ReadLine; +use JSON::PP qw(encode_json decode_json); + +my $cmd = do { + if (my $host = $ARGV[0]) { + 'cat jsonrepl.packed - | ssh '.$host.' perl -' + } else { + 'perl jsonrepl' + } +}; + +my $pid = open2(my $out, my $in, $cmd); + +my $read = Term::ReadLine->new('REPL'); + +while (1) { + my $line = $read->readline('re.pl$ '); + exit unless defined $line; + next unless length $line; + print $in encode_json([ EVAL => $line ])."\n"; + my $reply = decode_json scalar readline($out); + if ($reply->[0] eq 'MISTAKE') { + die "Botch: ".join(': ', @{$reply}[1,2]); + } + my $ret = $reply->[1]; + print $ret->{return}; + if ($ret->{stdout}) { + chomp($ret->{stdout}); + print "STDOUT:\n${\$ret->{stdout}}\n"; + } + if ($ret->{stderr}) { + chomp($ret->{stderr}); + print "STDERR:\n${\$ret->{stderr}}\n"; + } +}