This seems so simple, yet I can't find a solution that doesn't make my head hurt...

How can I capture STDOUT and STDERR of a child program in Win32 -- without letting cmd.exe get its grubby hands on my parameters, and sticking to the stuff in Perl core? (Since installing additional stuff everywhere isn't an option in this case, the core requirement rules out IPC::Run.)

The my $foo = `command` and system() approach (apparently) pass through cmd.exe, which breaks up parameters with spaces, not to mention the ugliness with non-7bit-ASCII characters. Apparently the construction documented under "Safe Pipe Opens" in PerlIPC and that I normally use, open(FH, '-|'), doesn't work on Win32. (It complains that - isn't a recognized command.) I looked at Win32::Process, which creates a process fine but doesn't seem to let me redirect the child's file handles.

So... how then to capture the child process' output?

I need to get its exit code too, but I assume that can be managed with $? and/or $proc_handle->GetExitCode().)

In reply to capture child process STDOUT/STDERR on Win32 by Ywleskvy

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.