Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: System call

by blueberryCoffee (Scribe)
on Feb 03, 2005 at 23:07 UTC ( #427860=note: print w/replies, xml ) Need Help??


in reply to System call

just use the backtick operator to get the system output. Perl will wait untill the program stops and then return the whole output. If this program writes to a file as you say then just ignor the output and open the file.

For example:
my $junk = `system call here`; # now open and process the file

Replies are listed 'Best First'.
Re^2: System call
by newuser_perl (Initiate) on Feb 04, 2005 at 00:29 UTC
    this is the sturcture of my perl scrip : -frist part of my perl script -system call to matlab (this needs to produce file A which doesnt exist so far) -second part of my perl script (this opens file A) do you just want me to change the system call to my $junk = `system call here`;? will this store file A in the same directory as my perl script? and will the second part of my perl script run only after the system call is done and it has produces file A? Thank you again
      Generally that's the idea - the output of `system call here` ends up in $junk ..

      But if `system call here` is a process - like a Matlab command - that creates an output file on its own, unless it writes the same output to STDOUT, you will likely not get it back in $junk.

      You definitely have to experiment, and note that the system command acts differently in that regard to the backticks or qx//.

      You can see the difference by running these two commands...
      perl -e 'use strict; my @n = qx!/bin/netstat -a|grep LISTEN|grep -v un +ix; sleep 4!; print $_ . $/ for @n;'
      and
      perl -e 'use strict; my @n = system("/bin/netstat -a|grep LISTEN|grep + -v unix; sleep 4"); print $_ . $/ for @n;'
      update - Unless of course, you are on Windows, then netstat and sleep probably won't work..

      Notice when using system(), @n gets printed right away, and with qx// the script waits until the external commands are done..

      If you do $junk = `system call here`;.. $junk will probably contain the Matlab command's exit code.. and you can then go open the new file A.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://427860]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2023-01-30 18:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?