I'm getting totally confused with getting my in- & outputs here.
I'm supposed to run some query-stuff in forks, using an old perl 5.6-window$-thing, and its basic pre-installed mods.

Trying a logout first, then a good login and further processing with other commands. It's not supposed to end or return to the shell, just needs to continue, hence my eval-tryout. If 'logout' doesn't find a valid login to finish, then he just asks for a user&passwd, in normal cmdline-situations through STDIN.

So, I've been trying to intercept that behaviour and send back the necessary values trough many different combinations. But I don't seem to manage...
Tried writing to STDIN, tried running from STDOUT, from $chld_frm, tried switching the parameters... Name it. (I actually never really tried mixing all those handles, so I guess that after copy-pasting-changing it's full of mistakes.)
I seem to start mixing all kind of file-handle-variable-types, without ever being able to read & write what open2 should be able to give me.
A prompt "User: ", and couple of milliseconds later "Passw: "...

HOOOOOOW????
So, for Perl's sake, don't get me losing my faith!
use Symbol qw( gensym ); use IPC::Open2 qw(open2); use Env; use IO::Select; use IO::File; use IO::Handle; use Data::Dumper; my ($chld_to,$chld_frm)=map gensym, 1..2; my $pid; print "Logging out first\n"; eval { select STDOUT; $|=1; $chld_to=*STDIN; $chld_frm=*STDOUT; select $chld_to; $|=1; select $chld_frm; $/=":"; $|=1; $pid=open2($chld_frm,$chld_to,"${bin_dir}system.exe","-logout") or + die "Could not launch LOGOUT: $? - $!"; sleep 2; print Dumper $chld_to; my $output=<$chld_frm>; print STDOUT "PID : $pid\n"; print STDOUT "OUTPUT (): $output\n"; if ($output =~ /^user/i) { print $chld_to "${USER}"; } if ($output =~ /^passw/i) { print $chld_to "${PASSW}"; + } waitpid($pid,0); close $chld_to; close $chld_frm; close EXH; }; if ($!) { print "Error loggin out: $? $!\n"; } else { print "Logged out: $? $! \n"; }

In reply to Open2, eval & handle-behaviour by Fré

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.