Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Is there a problem with IPC::Open on Windows 7?

by glasswalk3r (Pilgrim)
on Aug 06, 2013 at 19:53 UTC ( #1048172=perlquestion: print w/ replies, xml ) Need Help??
glasswalk3r has asked for the wisdom of the Perl Monks concerning the following question:

Greetings,

I was trying to use IPC::Open3 in a Windows 7 but I was getting the complaint below:

readline() on unopened filehandle

I found it intriguing since if I use the same program to fork a child process with IPC::Open2 it works as expected. Seems to be that STDERR is not being assigned as it would be expected.

To be sure, I wrote the two following scripts for testing:

use warnings; use strict; use feature 'say'; say 'foobar'; warn 'this is a warning';

And called it "dummy.pl".

Then I wrote:

use warnings; use strict; use IPC::Open3; use feature qw(say); my ( $wtr, $rdr, $err ); my $pid = open3( $wtr, $rdr, $err, 'perl', 'dummy.pl' ); while (<$rdr>) { print $_; } while (<$err>) { print $_; } close($err); close($rdr); close($wtr); waitpid( $pid, 0 );

After executing it, this is what I got:

c:\Temp>teste.pl this is a warning at dummy.pl line 7. foobar Use of uninitialized value $err in <HANDLE> at C:\Temp\teste.pl line 1 +5. readline() on unopened filehandle at C:\Temp\teste.pl line 15.

It looks like a bug, doesn't it?

I'm using Windows 7 Service Pack 1 with:

This is perl 5, version 16, subversion 3 (v5.16.3) built for MSWin32-x +86-multi-thread
Alceu Rodrigues de Freitas Junior
---------------------------------
"You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill

Comment on Is there a problem with IPC::Open on Windows 7?
Select or Download Code
Re: Is there a problem with IPC::Open on Windows 7?
by BrowserUk (Pope) on Aug 06, 2013 at 20:12 UTC

    Yes. It is broken on Windows. (If you print out the handles immediately after the open you'll find that $err is never set.)

    What to do about it? You could raise an bug report; but it's been broken for a decade or so already at least; it is unlikely to change anytime soon.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Is there a problem with IPC::Open on Windows 7?
by ikegami (Pope) on Aug 08, 2013 at 03:57 UTC

    It's not broken, and it's not Windows-specific. Passing undef for the third arg has a special meaning. This is covered in the first paragraph of the documentation, which refers to the Synopsis for how to achieve what you want.

    Note that you have a deadlock potential in your code. While the parent is blocked reading from the child's STDOUT, the child could block trying to write to its STDERR. I strongly discourage the use of this low-level module if you plan on reading from both the child's STDOUT and its STDERR. Instead, try IPC::Run3 or IPC::Run.

      It's not broken,

      It is broken. It may be "broken by design"; but it is broken.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        The design isn't broken either. It's perfectly simple and makes sense.

        open(\*IN, \*OUT, \*ERR, ...) # Get three pipes back open(\*IN, \*OUT, undef, ...) # Get two pipes back, # one catches both STDOUT and STDERR

        It's using lexicals that causes problems. This module predates lexicals.

      Instead of using globs or lexicals, I'm checking about using sockets instead of file handles as used in https://github.com/lucastheisen/ipc-open3-callback. So far, select seems to be working fine, but I need to do more tests (like generating something into the child process STDERR).

      Documentation of IPC::Open3 in the Synopsis uses use Symbol 'gensym', which could be applied to all three lexicals. If I'm not wrong, this is the approach used by IPC::Run or IPC::Cmd. Is this expected to fail too?

      Alceu Rodrigues de Freitas Junior
      ---------------------------------
      "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill
Re: Is there a problem with IPC::Open on Windows 7?
by xiaoyafeng (Chaplain) on Aug 08, 2013 at 07:02 UTC

    First, please read below contents aloud:

    Not all Perl programs have to be portable There is no reason you should not use Perl as a language to glue Unix tools together, or to prototype a Macintosh application, or to manage the Windows registry. If it makes no sense to aim for portability for one reason or another in a given program, then don't bother.

    perlport

    Secondly, run perldoc perlport, and read carefully. it explains clearly (I think) why perl and perl standard modules are also possible not usable in all support platforms....





    I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

      Well, my program needs to be portable between Linux, AIX, Solaris and MS Windows, so I'm not sure how taking this quote in consideration will help at all.

      Alceu Rodrigues de Freitas Junior
      ---------------------------------
      "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1048172]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2014-12-25 02:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls