hamburger-pimp has asked for the wisdom of the Perl Monks concerning the following question:

I'm running a script, and I have an outside pl/txt file that I need to run and use the output in the main script. How do i go about accessing the outside script and using the output in the main one that's already running?? Can anyone help with this? HP

Replies are listed 'Best First'.
Re: running an outside script
by vladb (Vicar) on Jun 22, 2002 at 20:21 UTC
    There's a very simple way to do it in Perl:
    my $prog_output = `shell_command 2&>1`; print "OUTPUT: $prog_output\n";
    At least this is what I have in a few of my smaller scripts (mostly throw-away) running in tcsh shell. The '2&>1' simply makes it so that all the error messages produced by the script (printed to the STDERR file handler) will also be 'sent' to STDOUT and consequently received by our script.

    There are of course other much better approaches. For example, take a look at vroom's explanation here. Or also take a look at the Perl interprocess communication document, especially the 'Using open() for IPC' section ;-)



    _____________________
    # Under Construction
Re: running an outside script
by Ryszard (Priest) on Jun 22, 2002 at 20:15 UTC
    You could (whoops) use backticks. my $output = `script.pl`;

    Insert security disclaimer here.

      I'm using active perl, and i've tried just that, and i'm getting a back command or file name issue...is there a remedy for this, or is there another approach I need? HP
        Make sure that other script is in your path or that you have given the full pathname in the backticks (`c:/windows/desktop/test.pl`). If that's already the case, you need to make sure your system assumes .pl files to be executable; otherwise, you have to precede the command with a call to Perl (`c:/perl/bin/perl.exe c:/windows/desktop/test.pl`).

        Makeshifts last the longest.

        If you haven't already resolved this, you might try:

        $return = qx(/path/to/perl external.pl);

        Update:I didn't see Aristotle's answer till after.