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

From a perltray application, I need to execute (and use the STDOUT output from) `netstat -e` every 15 minutes. With simple backticks, an annoying cmd window pops up every time it executes(sometimes stealing keystrokes meant for other windows during that moment). "open3" seems to prevent the perltray application from starting at all. Win32::Process can create a separate (and I understand, minimized) process, but I'm not sure how to capture STDOUT from the netstat (can you specify to Windows that it is a console application? or can you capture the filehandles with Win32::Process?) Or is there some other way to get the output of `netstat -e` without that cmd window popping up momentarily? Thanks in advance for any assistance, -- John
  • Comment on Backticks with no cmd window from perltray

Replies are listed 'Best First'.
Re: Backticks with no cmd window from perltray
by BrowserUk (Patriarch) on Nov 11, 2005 at 04:48 UTC

    See this article from Jenda, specifically the advice under the heading Subprocesses, which basically says add:

    BEGIN { Win32::SetChildShowWindow(0) if defined &Win32::SetChildShowWindow };

    to your GUI scripts, to cause child processes to be created with a hidden console.

    After that, using backticks to run netstat works fine.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Thanks everyone for your help!
      I checked the monitors available with the PerfMon library, but I'm looking for total bytes transferred, rather than bytes/second.
      The advice from the Jenda article, however, was exactly what I needed. Everything works perfectly now.
      Thank you!
      -- John
Re: Backticks with no cmd window from perltray
by NetWallah (Canon) on Nov 11, 2005 at 01:21 UTC
    Assuming you want to display ethernet (or other network-related) statistics, you could take another approach:
    Instead of running NETSTAT, use Win32::PerfMon; , and bind to the "Network Interface" object. All kind of goodies await there..

         "Man cannot live by bread alone...
             He'd better have some goat cheese and wine to go with it!"

Re: Backticks with no cmd window from perltray
by BUU (Prior) on Nov 11, 2005 at 01:05 UTC
    Your best bet is probably "open3" as you put it, so you'll probably have to explain why you think it prevents your script from running. Although you could also try just regular open.