> -----Original Message-----
> From: Gupta, Ashish [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, October 25, 2001 3:21 AM
> To: '[EMAIL PROTECTED]'
> Subject: system() and STDOUT & STDERR
>
>
> please help me solve another prob i am facing.
>
> i have 2 scripts --> a.pl and b.pl
> both scripts have a paramter called -logfile.
> if this is specified, the STDOUT and STDERR are redirected to this.
>
> now, I call b.pl from within a.pl
> using system().
>
> the documentation for system() says that the STDOUT, STDERR
> of the new
> process are inherited from the parent process.
> so, I expect that if I do not specify -logfile for b.pl but
> specify -logfile
> for a.pl, then the output for b.pl should also go to the
> logfile for a.pl
> but the output of b.pl is lost.
>
> if I do not specify the logfile for either script, then
> everything comes
> out fine on STDOUT.
>
> I am pasting the progs below :
>
> Thanks,
> Ashish
>
> #=======================
> # a.pl
> #=======================
>
> use Getopt::Long ;
>
> @cl = @ARGV ; # preserve for printing
> GetOptions (
> "logfile=s" => \$logfile
> );
>
> # if logfile defined, set it up.
> if (defined ($logfile)) {
> open (LOGFILE, ">>$logfile") or ERR_HANDLER
> ("main:LogFile:Cannot_Open") ;
> open (STDOUT , ">&LOGFILE"); # redefine STDOUT and STDERR to
> point to LOGFILE
> open (STDERR , ">&LOGFILE");
> $| = 1 ; # better if logs are updated
> instantly
> }
>
> print ("$0 :: Starting ...\n") ;
> print ("CommandLine : @cl\n") ;
> print ("calling b.pl ...\n\n");
> system ("b.pl") ;
> print ("$0 :: Finished ...\n") ;
>
> #====================
> # b.pl
> #====================
>
> use Getopt::Long ;
>
> @cl = @ARGV ; # preserve for printing
> GetOptions (
> "logfile=s" => \$logfile
> );
>
> # if logfile defined, set it up.
> if (defined ($logfile)) {
> open (LOGFILE, ">>$logfile") or ERR_HANDLER
> ("main:LogFile:Cannot_Open") ;
> open (STDOUT , ">&LOGFILE"); # redefine STDOUT and STDERR to
> point to LOGFILE
> open (STDERR , ">&LOGFILE");
> $| = 1 ; # better if logs are updated
> instantly
> }
>
> print ("$0 :: Starting ...\n") ;
> print ("CommandLine : @cl\n") ;
> print ("$0 :: Finished ...\n") ;
Are you sure b.pl is running correctly? You aren't checking the return value
of system().
Your scripts as posted do not have the #!/usr/bin/perl line, so
system("b.pl")
will be passed to the unix shell and not to perl.
Your example works fine for me, as long as I put the #!/usr/bin/perl lines
at the top. I get the following output in the log file:
a.pl :: Starting ...
CommandLine : -logfile test
calling b.pl ...
./b.pl :: Starting ...
CommandLine :
./b.pl :: Finished ...
a.pl :: Finished ...
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]