I've just played with this myself... and I think I can replicate your problem.  As I don't have findstr, I'm not entirely sure what it's doing, but I suppose it's some kind of 'grep', which reads lines from stdin, and writes lines to stdout if they match a given keyword.  So, I've used a little Perl program instead, which does the same.

The issue under Windows seems to be that the "close IN" in your script does not generate an end-of-file on stdin of the process spawned. So, the program keeps reading/writing... In other words - as it doesn't terminate yet - it doesn't close stdout either, which in turn means that your "@found = <OUT>" is waiting for more lines to come (i.e. it 'hangs').

The following test script demonstrates the issue:

#!/usr/bin/perl use strict; use warnings; use IPC::Open2; my $pid; eval { $pid = open2(\*OUT, \*IN, qw(perl -ne), '$|=1; print if /hello/i') +; }; if ($@ and $@ =~ /^open2:/) { die "$@:$!\n"; } my $sometext = <<END; Hello, World! END print IN $sometext; close IN; # read/print line by line, so we see the output while (<OUT>) { print ":: $_"; }

On Windows (tested with Perl 5.8.8 on XP), this prints ":: Hello, World!" and then hangs.  On Unix/Linux, it terminates after printing the line, as expected  (you can make it hang, too (like on Windows), by commenting out the line "close IN;").

Anyhow, I'm no Windows gal, so I'm afraid I can't help you any further...

BTW, an unrelated thing: in my original snippet, I had deliberately put the my $pid outside of the eval, because in case you'd need it later on, it would already have gone out of scope... — yes, you're not using it here, but just in case.

___

(PS: <PerlMonks-meta> I normally don't frontpage nodes where I'm the first/only one who has replied (feels like XP-whoring to me)... but in this case I did, in the hope that it'll get some more exposure, and that someone windows-savvy will know more... </PerlMonks-meta>)


In reply to Re^3: open2 on windows by almut
in thread open2 on windows by mangetsu

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.