#!/usr/bin/perl -w use strict; use IPC::Open2; # or IPC::Open3 my ($in,$out); $|=1; my $pid=open2($out,$in,'/usr/bin/ssh','foken@10.50.20.82','/usr/bin/perl'); print $in <<'__end_of_perl__'; $|=1; use strict; use warnings; print "ok, running with PID $$\n"; while () { chomp; print "File $_ has a size of ",-s($_)," bytes\n"; } # the next line is important: __END__ __end_of_perl__ print "Loaded\n"; print "Reading boot message: "; my $info=<$out>; print $info; for my $file ('/etc/passwd','/etc/motd','/etc/issue') { print "Requesting $file\n"; print $in "$file\n"; print "Reading: "; $info=<$out>; print $info; } #### Loaded Reading boot message: ok, running with PID 13498 Requesting /etc/passwd Reading: File /etc/passwd has a size of 1468 bytes Requesting /etc/motd Reading: File /etc/motd has a size of 20 bytes Requesting /etc/issue Reading: File /etc/issue has a size of 24 bytes