On Fri, 23 Aug 2019 19:16:55 +0300
Mario Galindez <mario.bidon.galin...@gmail.com> wrote:

> Folks,
> 
> 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);
> 
>     waitpid( $pid, 0 );
> 

Hi Mario,

see https://perl-begin.org/uses/remote-login-and-commands/ - use a CPAN dist.
Also note that https://metacpan.org/pod/IPC::Run is a commonly cited
alternative to IPC::Open3 .

Finally, see https://perl-begin.org/tutorials/bad-elements/ and
https://github.com/shlomif/Freenode-programming-channel-FAQ/blob/master/FAQ_with_ToC__generated.md#what-are-some-best-practices-in-programming-that-i-should-adopt
for some best practices advice.

> 
> 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 u...@remotehost.com, and type multiple
> lines of input, then things work as expected.
> 
> Any clues?
> 
> Thanks!
> -m



-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
http://www.shlomifish.org/humour/bits/Google-Discontinues-Services/

Knuth is not God! Typing “God” into Google and pressing “I’m Feeling Lucky”
will not lead you to his homepage.
    — http://www.shlomifish.org/humour/bits/facts/Knuth/

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to