Note that you pass references to the start methods:
# starting the application
my $handle = start \@args, \$in, \$out, \$err;
After the fact, those references are lost for you, since you don't save them. Then you store copies of the scalars $in, $out, $err into the hash %client_descr for later use. But alas, those values don't have any connection with the handles IPC::Run operates with. So you are using a $out later that isn't the one IPC::Run is using.
To fix that, either make your $in, $out, $err into references first and store those -
my ($in, $out, $err);
for($in,$out,$err) { $_ = \my $x }
# starting the application
my $handle = start \@args, $in, $out, $err;
# wait until prompted for input
pump $handle until $$out =~ /Login:/; # note the dereferencing
+- $$out
$in .= "Boris\n";
# wait until prompted for password
pump $handle until $$out =~ /Password:/;
# and so on ...
# store them
$client_descr->{"Handle"} = $handle;
$client_descr->{"In"} = $in;
$client_descr->{"Out"} = $out;
$client_descr->{"Err"} = $err;
- then you can use them in another sub too:
$in .= "new data\n";
pump $handle until $$out =~ /data arrived:/; # note the dereferencing
+- $$out
print $$out;
- or store references to those scalars into your hash:
$client_descr->{"Handle"} = $handle;
$client_descr->{"In"} = \$in;
$client_descr->{"Out"} = \$out;
$client_descr->{"Err"} = \$err;
# later ...
my ($handle, $in, $out) = ($client_descr->{"Handle"}, $client_descr->{
+"In"}, $client_descr->{"Out"});
$in .= "new data\n";
pump $handle until $$out =~ /data arrived:/; # note the dereferencing
+- $$out
print $$out;
Here the references IPC::Run operates with and those stored in the hash are different, but that is okay since both point to the same my scalars, which won't get destroyed until the references IPC::Run and your %client_descr hold are released.
You must use scalar dereferencing in "the other sub" since you cannot force $out in "the other sub" to have the same address as the original $out declared as a my variable in the first place, from which a reference was taken to pass it to start of IPC::Run.
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|