Hi I have a concern regarding executing a child process and get its output. My program uses perl Tk and my assigned task is to removed any appearing DOS Window when using my application. It should just shows Tk's GUI.

I have succesfully removed the DOS windows when starting the program and executing some applications using Win32::Process.

But this time, I need to execute a process and get its output. It seems that Win32::Process dont have function to get the output of a child process.

To be specific I am trying to run the following commandline and save its output to a buffer or file:

findstr /r /c:"$string" /f:"$file_list"

"findstr" command usually prints its output to STDOUT but I need to removed the DOS window. Is there a way of running a child process and redirect its output to variable or file without showing the DOS window?

I have used system(), open(FH,"commanline |"), exec(), and backticks but they are all showing the DOS window. When using Win32::Process it succesfully don't show the DOS Window but I cannot get the output of the child process.

I haven't try running cmd.exe itself using Win32::Process and use option to hide its window which I guest will work. But:
-"cmd /c" has limitation when using double quote(") and will not work to all double quote contained command lines.
-i don't know the perl function to get path of cmd.exe since using "set comspec" also shows its output in DOS Window.

I hope there's a feature in perl to solve my problem.


In reply to In Perl Tk: Run a commandline and get its output without showing the Console Window by toastbread

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.