I am trying to execute a small c utility (like sort, which is used in this example) from my perl script. I want to send data to it upfront. Then the utility will return the results.
The cookbook indicates that "Open2" will work for this type of "synchronous" usage. (I am using Win2000)
But my Perl script blocks w/o displaying anything...
Here is the Perl code I am using:
my ($reader, $writer) = (IO::Handle->new(), IO::Handle->new());
my $command = "sort /reverse";
eval
{
open2($reader, $writer, $command);
};
if ($@)
{ warn "CRAP $! $@ \n"; }
foreach (@data)
{ print $writer $_ ."\n"; }
close ($writer);
while ($_ = $reader->getline())
{print $_;}
close ($reader);
}
For debugging, I tried:
my $command = 'type test.dat | sort /reverse';
***This works***
What doesn't work is the Open2..$reader..$writer code...
I just can't figure out what is different...Does the shell handle this differently than Perl or is it EOF or CRLF or ???
Any HELP is REALLY appreciated, as I am probably missing a BIG "thing"
thanks!!!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.