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

Hello Monks,

One of the first things my web-based application does is run another program. The problem is that this program prints a bunch of stuff I am not interested in to STDOUT, which means that if I use system(), all of that stuff is printed to the browser, followed by the html text of my webpage.

What I want it to do is ignore all of that stuff being sent to STDOUT by this other program and wait until this other program is finished before continuing.

I know that this other program is done because it creates a text file that is parsed by the rest of my program.

My current hack is to use backticks to collect that STDOUT junk and wait until it is possible to open the text file before continuing:

my $out = `"python extractx.py $folder/junction.fasta"` wait until(open NULL, "$folder/junction.fasta.allseqs.txt");

This is all I could come up with, but I'm assuming that I could also temporarily change where STDOUT goes until the program is done, and then change it back to the default, but I'm not sure if that is possible or how to do it.

Thanks in advance for any help.

Replies are listed 'Best First'.
Re: STDOUT Issues
by FunkyMonk (Bishop) on Jun 27, 2007 at 21:35 UTC
    Redirect STDOUT to /dev/null

    system( "python extractx.py $folder/junction.fasta > /dev/null" )

    update: Assuming you're on a *nix system, of course.

    For Windows, redirect to a file in your temp folder (probably "c:\windows\temp").

      For Windows, redirect to a file in your temp folder (probably "c:\windows\temp").

      Windows has a sink device too: NUL. It dates back to at least DOS 3.

        That's something I probably knew 15 years ago. Fortunately, I don't do any windows development now:)

        Thanks for the reminder

Re: STDOUT Issues
by runrig (Abbot) on Jun 27, 2007 at 21:45 UTC
    The backticks should cause the program to wait until the command is done, you shouldn't have to wait until you can open the output file. Anyway, can't you just redirect the output of the command:
    system("command arg1 arg2 >/dev/null 2>&1");