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

I have a binary which print data to screen, but I need the data to be printed in a particular file. Since I cannot find the original sourcd code, one thing I can do is to write another program to capture whatever data printed to the screen. Normally we capture data from STDIN and print it to STDOUT. However, is there any way allowing getting data from STDOUT and print them into a particular file? Thanks.

Replies are listed 'Best First'.
Re: How to capture data from STDOUT?
by Biker (Priest) on Dec 20, 2001 at 13:43 UTC

    I may be misunderstanding the problem, but from your question I have the impression that this is not something you need to solve using Perl. (??)

    Executing:

    binprogram >somefile
    at the shell should do it.

    "Livet är hårt" sa bonden.
    "Grymt" sa grisen...

Re: How to capture data from STDOUT?
by Hofmator (Curate) on Dec 20, 2001 at 13:43 UTC

    If I read you correctly, you want to capture the output of a program and do _no_ processing of it, just store it to a file. In that case the simple name_of_binary > filename typed on your shell should be enough. Otherwise stick to Juerd's suggestion.

    -- Hofmator

      Hi, I have tried your advice and it worked well... Thanks!!
Re: How to capture data from STDOUT?
by Juerd (Abbot) on Dec 20, 2001 at 13:35 UTC
    Use backticks (qx//), or open() a pipe to the program.
    If it's a one-time-thing, you can also let your shell do the job: someprogram | perl yourscript.pl

    2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$