A few years ago, I wrote a magazine article detailing how to mix "main" and "WinMain" concepts in a Win32 program, and how the differences weren't exactly clear cut. I don't have a copy handy, alas.

However, I use stdout and stderr in GUI programs all the time, for debugging/logging. It's harmless and does nothing unless the program was started with redirected output. I think stdin is the same way: if you have a GUI program and don't supply a file handle when it's started (i.e. "redirect" it), it is connected to nothing. A Console program, on the other hand, will create a new console the first time it is needed, it it wasn't hooked up to anything (because it was launched by a GUI process or with flags telling it not to).

Hmm, on rereading, I think you don't need any of that. You are asking about ordinary command-line programs, right? Your problem is that | won't give you both input and output at the same time?

In that case, see the module IPC::Open2. It does exactly this.

—John


In reply to Re: redirecting stdin on windows by John M. Dlugosz
in thread redirecting stdin on windows by arkamedis21

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.