in reply to Filtering output from a system() call

Since you say "exe" I'm guessing this is Windows. On a UNIX system, the traditonal way to do this would be for the command you execute to be a shell command that redirects standard output to /dev/null or some other bit bucket:

myprogram > /dev/null
There are similar ways to redirect just standard error or both standard output and standard error if it's not that simple:
myprogram 2> /dev/null myprogram > /dev/null 2>&1
You can use IPC::Run to do this sort of thing (different syntax) without invoking a shell.

Replies are listed 'Best First'.
Re: Re: Filtering output from a system() call
by BrowserUk (Patriarch) on Feb 10, 2003 at 06:50 UTC

    The same syntax will work under Win32, the only difference being the name of the bit-bucket. Ie. nul

    It's worth pointing out that to redirect both handles you can do, mycommand 1>nul 2>nul or mycommand 1>nul 2>&1 or mycommand  2>nul 1>&2

    but that mycommand 1>&2 2>nul doesn't work as the first part redirects handle 1 (STDOUT) to wherever handle 2 is currently pointing (which is the same place as STDOUT at that point). The subsequent redirection of handle 2 to the nul device only redirects handle 2 and does not retro-actively re-redirect handle 1.

    I point this out only because I still get this wrong if I'm doing stuff in a hurry, and I've been doing so for 10+ years.


    Examine what is said, not who speaks.

    The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.