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

Im using system () to call an external executable from within perl. When the executable launches, it prints some banner junk I dont want displayed on the screen as it fuzzies up the analysis data i output on my own. Is there anyway to prevent output like this from an exe? The exe writes data to a logfile, which is really what Im after, and the extra banner stuff it dumps to the screen is just unwanted.

update (broquaint): title change (was System)

Replies are listed 'Best First'.
Re: Filtering output from a system() call
by diotalevi (Canon) on Feb 10, 2003 at 06:06 UTC
Re: Filtering output from a system() call
by steves (Curate) on Feb 10, 2003 at 06:23 UTC

    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.

      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.