in reply to Re: assign open2 output to variable
in thread assign open2 output to variable

THANKS!! this is great, i can get what i needed, i'm able to read through line by line what are the outputs. However, how will i be able to output the stream in real time while i'm collecting the data in CIN? Otherwise i'll have to flush out all outputs at one shot when the plink process is done? for this example, i'll use "ls" :
my $command = 'link -ssh -pw password_here user_name@host -batch'; $pid= open3(\*CIN, \*COUT, \*COUT, $command); print CIN "ls\n"; print CIN "exit\n"; close CIN; my @xs = <COUT>; foreach $x(@xs) { print "\noutput:".$x."\n"; } close COUT; waitpid( $pid, 0 );

Replies are listed 'Best First'.
Re^3: assign open2 output to variable
by ikegami (Patriarch) on Mar 31, 2014 at 16:05 UTC
    The following will print the output as its produced:
    while (<COUT>) { print; }

    Well, it prints it a line at a time. sysread can truly get it as its produced.

    Of course, plink might buffer its output. Lots of applications do when they're output isn't a terminal. If it does, you'll have to look if it provides a way to be told not to.