in reply to exec, system, or backticks

If you do something like:

`$swbt_dms $item > $log/$key`; $key = ...read file $log/$key...

Then you could simply do:

$key = `$swbt_dms $item`;

Otherwise, it's a waste to use `` when you discard the return value::

$key = system("$swbt_dms $item");

In Windows, you could also use Win32::Process and call $process->Wait().

exec is not appropriate since it doesn't return.

fork+exec, IPC::Open2, IPC::Open3, system 1, (Win32) and Win32::Process without $process->Wait() (Win32) are not appropriate since they create a process that runs in parallel.

Replies are listed 'Best First'.
Re^2: exec, system, or backticks
by tc1364 (Beadle) on Oct 20, 2004 at 17:29 UTC
    I need to capture the output from the Expect script so that it can be evaluated and this is why the backticks were used, but if the ouput from the Expect script ($swbt_dms) can be captured without the use of backticks this would be great. The arguement ($item) provided to the Expect script is either Datakit or IP info. So with all of this said, what would be the most appropriate method of capturing into a file (has to be into a file) the output from the Expect script so that it can be evaluated? Hay, thank you for taking time to help me with elevating my Perl knowledge.

      I'm not sure what you mean by evaluate. If you mean executed as perl code, how about eval ``:

      $ perl -e 'eval `echo print 1+3`'; 4

      Otherwise, system will do just fine:

      $ perl -e 'system("echo bla > file");' $ cat file bla
        What I mean by evaluate is this, the output from the Expect script is sent to a file where the sub ck_results opens the file and checks to determine if the necessary information was collected or not and then closes the file. For example, the Expect asks the other box/server to provide it specific register information so that anaylsis of this information can be done.
        Thank you for your help my code was modified as follows: <code> system("$swbt_dms $item > $log/$key"); <code> It work just fine. Thank you again!