Can't read from open2

P

Pranab Mehta

Hi All,

I'm trying to automate data entry to a windows app using wine from my
linux machine. I'm not very proficient with my Perl, hence this post.
Pretty simple scenario, I kick off a process, write to it, and then
want to read from it. But nothing ever prints in the output. Here's
the code in question -

$pid = open2(READHDLR, WRITEHDLR, "wine win_app.exe") or die "can't
run command: $!";
WRITEHDLR->autoflush();
READHDLR->autoflush();
print "PID = $pid\n";

print WRITEHDLR $PIN;
print WRITEHDLR "\x0d\x0a";

$got=<READHDLR>;
print "output = $got";


Now if I were to replace READHDLR with a FILEHANDLE for writing, like
this:
open(OUTFILE, "> outfile");
open2(">&OUTFILE", ...);
I can see _all_ the data from the win_app in the file. Then why can't
I read this data from READHDLR ?

Further, I don't know if this is valid, but if I pipe the output of
READHDLR to a file, like this:
open(READHDLR, "| tee outfile");
the file turns out empty.

What am I missing ?
Please someone set me on the right path ...

Thanks much,
Pranab
 
B

Bob Walton

Pranab Mehta wrote:

....
I'm trying to automate data entry to a windows app using wine from my
linux machine. I'm not very proficient with my Perl, hence this post.
Pretty simple scenario, I kick off a process, write to it, and then
want to read from it. But nothing ever prints in the output. Here's
the code in question -

$pid = open2(READHDLR, WRITEHDLR, "wine win_app.exe") or die "can't
run command: $!";
WRITEHDLR->autoflush();
READHDLR->autoflush();
print "PID = $pid\n";

print WRITEHDLR $PIN;
print WRITEHDLR "\x0d\x0a";

$got=<READHDLR>;
print "output = $got";


Now if I were to replace READHDLR with a FILEHANDLE for writing, like
this:
open(OUTFILE, "> outfile");
open2(">&OUTFILE", ...);
I can see _all_ the data from the win_app in the file. Then why can't
I read this data from READHDLR ?

Further, I don't know if this is valid, but if I pipe the output of
READHDLR to a file, like this:
open(READHDLR, "| tee outfile");
the file turns out empty.
....


Just a guess ... perhaps your win_app.exe is buffering its output? If
so, the output won't appear until a bufferful has been generated. Can
your win_app.exe be recompiled with output buffering turned off? If so,
try that. Or try a test program in place of win_app.exe which has
buffering turned off (like maybe an itsy-bitsy Perl program).

HTH.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,059
Members
48,769
Latest member
Clifft

Latest Threads

Top