mgalindez has asked for the wisdom of the Perl Monks concerning the following question:
I need to execute a program in a remote machine, that takes its input from STDIN.
I created a user in such remote machine, and set my program as the shell for that account (so I don't need to provide shell access).
On my local node, I have this program:
#!/usr/bin/perl use IPC::Open3; use POSIX; $inputfile= $ARGV[0]; open(FILE, '<', "$ARGV[0]") or die $!; $command= "ssh user\@remotehost.com"; $pid = open3('<&FILE', '>&STDOUT', '>&STDERR', $command); $ret=waitpid( $pid, 0 );
What I expect is that I pass the name of the file as arguments of this program ($ARGV[0]), and the contents of this file is fed as STDIN of the child I've spawn with open3. This should be received as STDIN of my remote program, and the results of the remote program would be printed on STDOUT.
This works well. However, my program only reads the first line, and then terminates.
If I do a manual test, and do ssh user@remotehost.com, and type multiple lines of input, then things work as expected.
Any clues?
Thanks!
-m
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem executing command via ssh
by haukex (Archbishop) on Aug 23, 2019 at 21:05 UTC | |
|
Re: Problem executing command via ssh
by jcb (Parson) on Aug 23, 2019 at 23:12 UTC | |
by haukex (Archbishop) on Aug 24, 2019 at 06:53 UTC | |
by mgalindez (Initiate) on Aug 25, 2019 at 13:54 UTC | |
by jcb (Parson) on Aug 25, 2019 at 23:55 UTC |