Redirecting stdout/stderr from a call to system() 
Author Message
 Redirecting stdout/stderr from a call to system()

I have a perl script which runs several shell commands (including a
couple C programs I've written) using system(). This perl script runs
from crontab, under Solaris, like so:

30 10 * * 1-6 /bindir/foo.pl >>/logdir/foo.log 2>&1

The output printed directly from foo.pl goes into foo.log, but the
output of the shell commands run with system() from within foo.pl
doesn't apear in the log file... how can I make sure this output also
goes to the log?

Sent via Deja.com
http://www.*-*-*.com/



Sat, 26 Jul 2003 00:53:35 GMT  
 Redirecting stdout/stderr from a call to system()

Quote:

> I have a perl script which runs several shell commands (including a
> couple C programs I've written) using system(). This perl script runs
> from crontab, under Solaris, like so:

> 30 10 * * 1-6 /bindir/foo.pl >>/logdir/foo.log 2>&1

> The output printed directly from foo.pl goes into foo.log, but the
> output of the shell commands run with system() from within foo.pl
> doesn't apear in the log file... how can I make sure this output also
> goes to the log?

are you sure your utils are being executed?  Try giving the fully
qualified path to the utils and avoid using ~ to mean your home
directory.

B

Sent via Deja.com
http://www.deja.com/



Sat, 26 Jul 2003 01:01:44 GMT  
 Redirecting stdout/stderr from a call to system()

Quote:

> I have a perl script which runs several shell commands (including a
> couple C programs I've written) using system(). This perl script runs
> from crontab, under Solaris, like so:

> 30 10 * * 1-6 /bindir/foo.pl >>/logdir/foo.log 2>&1

> The output printed directly from foo.pl goes into foo.log, but the
> output of the shell commands run with system() from within foo.pl
> doesn't apear in the log file... how can I make sure this output also
> goes to the log?

perldoc is your friend...

perldoc -q stderr

amonototd

--


  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|

Sent via Deja.com
http://www.deja.com/



Sat, 26 Jul 2003 01:04:53 GMT  
 Redirecting stdout/stderr from a call to system()


Quote:


>how can I make sure this output also
> > goes to the log?

> are you sure your utils are being executed?  Try giving the fully
> qualified path to the utils and avoid using ~ to mean your home
> directory.

Yes, the output file from my C program's there with the right mdate...
it's log output's just not in the log file. I've also been using full
paths all along since the C program isn't in $PATH or even in the home
directory tree.
In case this helps, my system calls look like the following:

if(system "shell_cmd $FOOFILE $FOOFILE.old") {
    die "Bummer\n";

Quote:
}

... it's not dying, BTW :)

Sent via Deja.com
http://www.deja.com/



Sat, 26 Jul 2003 01:26:31 GMT  
 Redirecting stdout/stderr from a call to system()
with system() from within foo.pl

Quote:
> >how can I make sure this output also
> > goes to the log?

> perldoc is your friend...

> perldoc -q stderr

It says that the output from system should go the the same place as the
output from my perl script... that appears not to be happening in this
case. Uneless there's something I'm missing.
It also lists using backticks, but then I'd have to capture the output
in a variable and explicitly print it which seems like a stupid way to
do it to me so I'd like to avoid that.

Sent via Deja.com
http://www.deja.com/



Sat, 26 Jul 2003 01:29:44 GMT  
 Redirecting stdout/stderr from a call to system()

Quote:

> with system() from within foo.pl
> > >how can I make sure this output also
> > > goes to the log?

> > perldoc is your friend...

> > perldoc -q stderr

> It says that the output from system should go the the same place as
the
> output from my perl script... that appears not to be happening in this
> case. Uneless there's something I'm missing.
> It also lists using backticks, but then I'd have to capture the output
> in a variable and explicitly print it which seems like a stupid way to
> do it to me so I'd like to avoid that.

> Sent via Deja.com
> http://www.deja.com/

perldoc -q stderr
(...)
To read both a command's STDOUT and its STDERR
separately, it's easiest and safest to redirect them
separately to files, and then read from those files when
the program is done:

    system("program args 1>/tmp/program.stdout 2>/tmp/program.stderr");
(...)

You can also make your own:
close (STDERR);
close (STDOUT);
open (STDERR, "> /path/to/my_stderr.txt");
open (STDOUT, "> /path/to/my_stdout.txt");
(...)
close (STDERR);
close (STDOUT);

amonotod

--


  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|

Sent via Deja.com
http://www.deja.com/



Sat, 26 Jul 2003 01:49:34 GMT  
 Redirecting stdout/stderr from a call to system()


Wed, 18 Jun 1902 08:00:00 GMT  
 Redirecting stdout/stderr from a call to system()
Not sure exactly how, but I did.

I finally got regular shell commands to go to the log file, except they
were out of sync with the output of the perl script. The output of my C
programs still wasn't showing up at all.

To fix the former, I turned off buffering on stdout and stderr by adding

select((select(STDOUT), $|=1)[0]);
select((select(STDERR), $|=1)[0]);

This, for some reason, also fixed the latter problem.

I must confess I can't figure out what the heck happened and if anyone
does know, I'm curious to find out.

Sent via Deja.com
http://www.deja.com/



Mon, 28 Jul 2003 07:31:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. redirecting stdout and stderr within system()

2. redirecting stdout and stderr within system()

3. system() calls dont print to STDOUT or STDERR?

4. Having STDERR go to STDOUT in a system call

5. Having STDERR go to STDOUT in a system call

6. problem redirecting stderr during a system call

7. HELP - with redirect of STDERR and STDOUT

8. redirect STDERR to STDOUT ?????

9. redirecting stderr and stdout

10. writing to terminal even with STDOUT and STDERR redirected

11. assigning STDERR whild redirecting STDOUT to a file

12. Problem with redirecting STDOUT and STDERR

 

 
Powered by phpBB® Forum Software