Re: Problem re-directing STDOUT in system() calls

2000-03-29 Thread Steve Hay

"Andrei A. Voropaev" wrote:

> See the guide. Under modperl the output from system will not go to the
> user unless your perl was compiled with sfio. The reason for that I
> guess is that under modperl STDOUT is tied to a package, while system
> commands expect file descriptor. The easiest way to overcome it is to
> use `` (backtics) and capture all output into variable and then print
> it out.
>
> Andrei

The guide actually says:

3.5.5  Output from system calls
Output of system(), exec(), and open(PIPE,"|program") calls will not be
sent to the browser
unless your Perl was configured with sfio.

which is fair enough, but does it explain the problem I've got?

It DOES explain why the following script prints the output of IPCONFIG in the
browser when running under Apache and doesn't when running under Apache +
mod_perl:

$| = 1;
print "Content-Type: text/plain\n\n";
$status = system "D:\\WINNT\\system32\\ipconfig.exe";
print "The system() call exited with status $status.\n";

but that isn't my problem.

How does it explain why the following works under Apache 1.3.6 + mod_perl and
not under Apache 1.3.12 + mod_perl:

print "Content-Type: text/plain\n\n";
$status = system "D:\\WINNT\\system32\\ipconfig.exe > D:\\Temp\\ip.txt";
print "The system() call exited with status $status.\n";

?

I'm not trying to get the output of the system() call into the browser - I
want to re-direct it to a file - and the difference between the one which
works and the one which doesn't work is not mod_perl: it's the Apache version!

Am I also correct in thinking that configuring Perl with sfio is only an
option on Unix (which, BTW, doesn't have my problem anyway!)?

Help!


Steve Hay





Problem re-directing STDOUT in system() calls

2000-03-29 Thread Steve Hay

Hi,

I've had this problem before, but never got to the bottom of it.

I'm cursed with a situation in which I need to run some .exe file from a
(mod)perl script.  The program concerned is a console application so it
just writes its output on STDOUT.  I need to re-direct that output to a
temporary file, and then read the file in to process in the perl script.

Sounds simple enough, and it works fine running Apache without
mod_perl.  But as soon as I put mod_perl into the equation I find that I
can't re-direct STDOUT in the system() call.  The following script
illustrates the problem:

print "Content-Type: text/html\n\n";
$status = system "D:\\WINNT\\system32\\ipconfig.exe >
D:\\Temp\\ip.txt";
print "The system() call exited with status $status.\n";

Without mod_perl this works fine: "ip.txt" is created and $status is 0.
But with mod_perl "ip.txt" is not created, $status is 256 and the
following line appears in error.log:

The handle could not be opened
during redirection of handle 1.

Can anyone help?


My setup is as follows:

- NT 4 Workstation, Service Pack 6

- Perl 5.005_03 built with VC++ 6 and the Makefile options:
CFG = Optimize
USE_PERLCRT
PERL_MALLOC

- Apache 1.3.12 built with VC++ 6

- mod_perl 1.22 built with VC++ 6

- D: is a local disk which I have full access to


I've found that the problem goes away if I downgrade to Apache 1.3.6 and
keep everything else the same!


Steve Hay