Let's see: ssh does not touch the STDIN, STDOUT, STDERR streams. But it invokes the remote standard shell to handle arguments. So, get rid of the shell parsing.

Perl can read a program from STDIN, it stops reading at EOF or when it finds the magic "__END__" marker on a line. So, feed the remote Perl a program that implements some kind of read-eval-print loop (you may also call that a RPC server, if you wish), then send commands over STDIN, read results back from STDOUT.

Working (stupid) example:

#!/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/pe +rl'); print $in <<'__end_of_perl__'; $|=1; use strict; use warnings; print "ok, running with PID $$\n"; while (<STDIN>) { 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; }

Output:

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

To do:

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re: safely passing args through ssh by afoken
in thread safely passing args through ssh by perl5ever

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.