system(@ssh) steals stdin

M

Marc Girod

Hello,

Only partly a Perl question...

For some reason (don't ask...) I need to read data from stdin after
having invoked a program remotely, with ssh.
Surprise: there is nothing there...
Demo:

$ cat rsdtin
#!/usr/bin/perl -w

use strict;
use warnings;

my @ssh = qw(/usr/bin/ssh -q);
system(@ssh, qw(myhost /bin/date));
my @a = <>;
print "a: @a\n";
$ cat << eot | rstdin
aaa
bbb
eota:
$

Something I miss?
I thought of using Net::SSH::perl, but I had some problems to install
it (or some dependency) in a way which would work on both Solaris 8
and 10...

Thanks,
Marc
 
R

Randal L. Schwartz

Marc> Hello,
Marc> Only partly a Perl question...

Marc> For some reason (don't ask...) I need to read data from stdin after
Marc> having invoked a program remotely, with ssh.
Marc> Surprise: there is nothing there...

No surprise for me. In general, the child process started by system()
inherits Perl's stdin, stdout, and stderr. Your "ssh" is very likely
reading stdin in anticipation of sending it to the remote host.

If you tried the same trick with:

system "ssh myhost /bin/date </dev/null";

Or even:

system "date";

I'm sure you'd see a different output.

So it's not "system" stealing your input. It's ssh.

print "Just another Perl hacker,"; # the original
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,034
Messages
2,570,356
Members
47,002
Latest member
RobertoLip

Latest Threads

Top