[prev in list] [next in list] [prev in thread] [next in thread] 

List:       apache-modperl
Subject:    Re: Problem with perl system() function
From:       Brian Reichert <reichert () numachi ! com>
Date:       2004-04-29 18:35:51
Message-ID: 20040429183551.GN335 () numachi ! com
[Download RAW message or body]

On Wed, Apr 28, 2004 at 03:55:23PM -0400, Alejandro Galue wrote:
> 
> I tried this (inside the handler):
> 
> ...
> my $cmd = '/opt/reports/bin/getdata';
> system($cmd, @params);
> if ( open(DATA, '/opt/reports/var/data.txt') ) {
>     local $_;
>     while (<DATA>) { $r->print($_) }
>     close DATA;
> } else {
>     $r->print("<h1>Can?t read data</h1>");
> }
> ...
> 
> The program getdata put output in /opt/reports/var/data.txt

It may just be an example, but this handler doesn't create a unique
file; it may get stomped my multiple invokations.

Why not

  open(DATA, join(' ', $cmd, @params, '|') || croak "$cmd failed: $? $!\n";

if you're trying to avoid generating a text file.

I wrote the System2 module to get STDERR and STDOUT returned in
scalars (and avoid the Bourne shell); see if that'd be useful for
you...

  my ($out, $err) = system2(@args);

Are you checking on the exit status of your command?

  my ($exit_value, $signal_num, $dumped_core) = &System2::exit_status($?)?

Good luck...

-- 
Brian Reichert				<reichert@numachi.com>
37 Crystal Ave. #303			Daytime number: (603) 434-6842
Derry NH 03038-1713 USA			BSD admin/developer at large	

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic