dave_usa has asked for the wisdom of the Perl Monks concerning the following question:

Greetings,

I have the following problem. I have a script running on Windows machine that forks (creates a thread) and the parent thread calls system() to execute a process. After it forks, the parent thread redirects STDOUT to a file and the child reads it. Before the system() call is made, another redirection takes place, so the result of the process is saved to another file. When system() finishes the STDOUT is redirected back to the file.

Now, this was working correctly with the Perl version 5.6.1. However, it is not working with Perl 5.8. The created process prints to the console (typical STDOUT) of the parent process. I believe that it is has to do something with PerlIO. I have read somewhere, but I can't find it now, that one can redirect the underlying C filehandle instead of the Perl filehandle, STDOUT in this case.

Any ideas?
--Dave

Edit by tye, preserve formatting

  • Comment on fork system() STDOUT redirection on WindowsXP

Replies are listed 'Best First'.
Re: fork system() STDOUT redirection on WindowsXP
by Anonymous Monk on Jun 25, 2003 at 22:37 UTC
    Wasn't Perl's threads implementation worked up somewhat from 5.6.1 to 5.8.0 with the introduction of the threads pragma (as opposed to the Thread module and related)? Might this be a source of backwards incompatibility instead of (or in addition to) PerlIO?
      It is not clear to me how much fork implementation on Windows depends on the Thread module.
      --Dave
Re: fork system() STDOUT redirection on WindowsXP
by BrowserUk (Patriarch) on Jun 25, 2003 at 21:48 UTC

    Do you have a small testcase that demonstrates the difference you describe between 5.6.1 and 5.8?


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


      I do not know what you mean. The script is the same, only the Perl version changed.

        I was asking you to post a 'cut-down-to-the-bare-essentials-to-demonstrate-the-problem' version of your script. Trying to debug code based a verbal description of it is like trying to diagnose car trouble from "It makes a sort of cluck-clunk-weeee sound and then stalls":)

        It sounds from your description that this is probably a small part of a large script. If you reduce it to something that just demonstrates the failure, it would save anyone trying to help you from having to invent there own test script based upon guesses of what you might be doing.


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller