system() behavior

S

skochkarev

Hi,

I'm new to perl and find it strange sometimes. So, my question is.

As stated to perldoc, system() does not output. This is true for my
console application. But when I port it to Apache/cgi, it starts to
display all output. This is highly unwanted. Can I turn it off?

Another question. The `` works just I want with one difference: it
seems like perl does not stop until the `` finishes (but the rest of
my program needs `` finished). What operator should I put to make perl
wait until `` finishes?

Here is the piece of code:

-----------------------------------------------------------------------------------
my $cmdline = "c:\\tools\\decomp.bat";
my $param1 = "$tempdir";
my $param2 = "C:$tempfile";

my @args = ("$cmdline", "\"$param1\"", "\"$param2\"");
------ This operator puts all output to the browser ------------
system(@args);

------ This operator does not stop processing ------------
my $output = `$cmdline $param1 $param2`;

------- Code that reads files created by decomp.bat --------

Thanks in advance!
 
D

Darren Dunham

Hi,

I'm new to perl and find it strange sometimes. So, my question is.

As stated to perldoc, system() does not output.

Where does it say that?

system() doesn't output itself, nor does it capture output. But the
program that system() runs may output.
This is true for my
console application. But when I port it to Apache/cgi, it starts to
display all output. This is highly unwanted. Can I turn it off?

Have whatever system() is running not output. Maybe you want to
redirect the output to a file or to /dev/null....
Another question. The `` works just I want with one difference: it
seems like perl does not stop until the `` finishes (but the rest of
my program needs `` finished). What operator should I put to make perl
wait until `` finishes?

I don't know what youe mean with that sentence.
Here is the piece of code:

------ This operator puts all output to the browser ------------
system(@args);

------ This operator does not stop processing ------------
my $output = `$cmdline $param1 $param2`;

Both system and `` will wait until the command completes before
returning.
 
X

xhoster

Hi,

I'm new to perl and find it strange sometimes. So, my question is.

As stated to perldoc, system() does not output.

It says that system does not *capture* output. Instead, the output
leaks out to the started program's stdout, which is usually the same thing
as the parent's STDOUT.
This is true for my
console application. But when I port it to Apache/cgi, it starts to
display all output. This is highly unwanted. Can I turn it off?

redirect stdout to /dev/null, or whatever Windows equiv of that is.
Another question. The `` works just I want with one difference: it
seems like perl does not stop until the `` finishes

I don't know what that means. Perl doesn't restart until `` finishes,
it just sits in the `` operation and wait for it finish.
(but the rest of
my program needs `` finished). What operator should I put to make perl
wait until `` finishes?

That is already what it does.

------ This operator does not stop processing ------------
my $output = `$cmdline $param1 $param2`;

What does that mean? What are you seeing?

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
J

Jürgen Exner

As stated to perldoc, system() does not output.

That is not true. Or maybe it is, depending upon what you mean by "does
not output".
- the system() command does not _produce_ any output. If you want that
use print()
- it also doesn't capture or influence the output generated by the
command that is called. If the called command produces output, then it
will be displayed just as if system() was never involved.
This is true for my
console application. But when I port it to Apache/cgi, it starts to
display all output. This is highly unwanted. Can I turn it off?

If you script behaves differently from a command line then when run as a
CGI program, then you may want to investigate why. A good place to start
is some CGI newsgroup.
As for turning output off: well, system() doesn't produce any output in
the first place. You will have to silence whatever external command you
are running, maybe by using some option of that command if available or
by redirecting that commands output to a file or /dev/null or something
along that line.
Another question. The `` works just I want with one difference: it
seems like perl does not stop until the `` finishes (but the rest of
my program needs `` finished).

Ahhhmmm, no. system() and qx() (aka ``) will both stop execution of the
perl program until the external command has returned.
Maybe you are running the external command in the background, such that
the calling shell returns immediately?
What operator should I put to make perl
wait until `` finishes?

`` does wait for the external program to return. Your problem is with
the external program. Maybe it launches child processes in the
background?
Here is the piece of code:

-----------------------------------------------------------------------------------
my $cmdline = "c:\\tools\\decomp.bat";
my $param1 = "$tempdir";
my $param2 = "C:$tempfile";

my @args = ("$cmdline", "\"$param1\"", "\"$param2\"");
------ This operator puts all output to the browser ------------
system(@args);

No, it doesn't. system() happily ignores any output from the called
program. It's that external program that creates the output.

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top