experchange > perl

Mario Galindez (08-25-19, 04:11 PM)
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 -T 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, and type multiple lines of input, then things work as expected.

Any clues?

Thanks!
-m
Rainer Weikusat (08-25-19, 10:12 PM)
Mario Galindez <mario.bidon.galindez> writes:
[..]
> 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.


When a real hostname instead of XXXX, the perl code below works as you
expected it to work. This suggests an issue with the remote command
you're using.
Grant Taylor (08-27-19, 11:40 PM)
On 8/25/19 8:11 AM, Mario Galindez wrote:
> Any clues?


Why are you using "-T" on your ssh command? That "Disable
pseudo-terminal allocation.". I don't know what the lack of a PTY will
do to your program or it's interaction with STDIN & STDOUT.

Did you by chance mean to use "-tt" to force the allocation of a PTY?

Note: Manual interaction is likely automatically allocating a PTY.
Similar Threads