Ask a Question related to PERL Beginners, Design and Development.
-
Larry Guest #1
Redirect stdout, stderr to file and stdout
I have a small script that does some admin work for me.
What I need to do now is not only have is display information to STDERR
and STDOUT but also write the same information I see when I run the
command to a file.
I have written it for others who are not very technical. I want them to
be able to see the script working and what it is doing. But I also need
a log file of the same information so I can have it mailed to me and
keep a copy on the server.
I cant seem to get this to work.
Larry Guest Guest
-
#39215 [NEW]: Inappropriate close of stdin/stdout/stderr
From: tstarling at wikimedia dot org Operating system: Linux & Windows PHP version: 5CVS-2006-10-20 (CVS) PHP Bug Type: ... -
Run one process and get the stdout and stderr
I need to run one program and get the stdout and stdin from it. If possible in real time. like: perl myscript.pl "perl -e 'foreach (1..5)... -
[PHP-DEV] STDOUT, STDERR not defined in CLI mode
--=-jireo02uumYPe7EiBc0D Content-Type: text/plain Content-Transfer-Encoding: 7bit Hi, sometimes STDIN, STDOUT and STDERR are not defined in... -
1.8.0, fcgi and $stdout/$stderr
--gBBFr7Ir9EOA20Yy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline I have just been trying to get fcgi to run under... -
redirecting stdout/stderr on execl
consider the following code: ofstream logFile("out.txt"); streambuf *outbuf = cout.rdbuf(logFile.rdbuf()); streambuf *errbuf =... -
Drieux #2
Re: Redirect stdout, stderr to file and stdout
On Jan 16, 2004, at 5:02 PM, Larry Guest wrote:
Here's a bit of a wacky Idea - solve it by> I have a small script that does some admin work for me.
>
> What I need to do now is not only have is display information to STDERR
> and STDOUT but also write the same information I see when I run the
> command to a file.
>
> I have written it for others who are not very technical. I want them
> to
> be able to see the script working and what it is doing. But I also
> need
> a log file of the same information so I can have it mailed to me and
> keep a copy on the server.
a bit of indirection - namely write the
code so that it does what you want it to do
then nest it inside of a script like say
#!/bin/sh
myPerlCode 2>&1 | tee /tmp/myOutput.$$
mail me -s "command run" < /tmp/myOutput.$$
/bin/rm -f /tmp/myOutput.$$
that way your perl code remains simple, but what you
hand out to the users to use is going to deal with
all of the STDOUT|STDERR as well a always sending
you the email...
ciao
drieux
---
Drieux Guest
-
Paul Johnson #3
Re: Redirect stdout, stderr to file and stdout
On Fri, Jan 16, 2004 at 05:02:52PM -0800, Larry Guest wrote:
You don't say what OS you are on, but on *nix I would do something like:> I have a small script that does some admin work for me.
>
> What I need to do now is not only have is display information to STDERR
> and STDOUT but also write the same information I see when I run the
> command to a file.
>
> I have written it for others who are not very technical. I want them to
> be able to see the script working and what it is doing. But I also need
> a log file of the same information so I can have it mailed to me and
> keep a copy on the server.
>
> I cant seem to get this to work.
$ perl -le 'print STDERR "stderr"; print "stdout"' 2>&1 | tee output.txt
Solutions in Perl take more effort, but we can discuss them if necessary.
--
Paul Johnson - [email]paul@pjcj.net[/email]
[url]http://www.pjcj.net[/url]
Paul Johnson Guest
-
Tim Johnson #4
RE: Redirect stdout, stderr to file and stdout
One quick and dirty solution that I've used for some debugging in the
past is to create a subroutine called PrintOut();
###############################
use strict;
use warnings;
open(OUTFILE,">mylog.txt") || die;
PrintOut("Hello World\n");
sub PrintOut{
print @_;
print OUTFILE @_;
}
###############################
-----Original Message-----
From: Larry Guest [mailto:larry@opsource.net]
Sent: Friday, January 16, 2004 5:03 PM
To: [email]beginners@perl.org[/email]
Subject: Redirect stdout, stderr to file and stdout
What I need to do now is not only have is display information to STDERR
and STDOUT but also write the same information I see when I run the
command to a file.
Tim Johnson Guest
-
John McKown #5
Re: Redirect stdout, stderr to file and stdout
On Fri, 16 Jan 2004, Larry Guest wrote:
What have you tried? I would alter the script to have multiple print> I have a small script that does some admin work for me.
>
> What I need to do now is not only have is display information to STDERR
> and STDOUT but also write the same information I see when I run the
> command to a file.
>
> I have written it for others who are not very technical. I want them to
> be able to see the script working and what it is doing. But I also need
> a log file of the same information so I can have it mailed to me and
> keep a copy on the server.
>
> I cant seem to get this to work.
>
statements. One to STDERR or STDOUT, the other to my file. Something like:
open(LOGGER,'myfile.log');
....
print STDERR "$message\n";
print LOGGER "$message\n";
....
If you want, you could "encapsulate" this by not using print directly, but
in your own function, say "myprint()".
sub myprint {
my $fn = shift;
print $fn "@_";
print LOGGER "@_";
}
my $STDOUT=\STDOUT;
my $STDERR=\STDERR;
....
my $message="This is a test.\n";
....
&myprint($STDOUT,$message);
....
&myprint($STDERR,$message);
Hope this is useful in some way.
--
Maranatha!
John McKown
John McKown Guest
-
Randal L. Schwartz #6
Re: Redirect stdout, stderr to file and stdout
>>>>> "Larry" == Larry Guest <larry@opsource.net> writes:
Larry> I have a small script that does some admin work for me.
Larry> What I need to do now is not only have is display information to STDERR
Larry> and STDOUT but also write the same information I see when I run the
Larry> command to a file.
Larry> I have written it for others who are not very technical. I want them to
Larry> be able to see the script working and what it is doing. But I also need
Larry> a log file of the same information so I can have it mailed to me and
Larry> keep a copy on the server.
Larry> I cant seem to get this to work.
I think this might do it:
open TEE, "| tee YourLogFileHere";
open STDOUT, ">&TEE";
open STDERR, ">&TEE";
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Randal L. Schwartz Guest
-
Larry Guest #7
RE: Redirect stdout, stderr to file and stdout
This is very close.
But the script hangs and wont exit the "tee" command.
I ran the script using "strace" and it sits there like this.
write(1, "Backup and Replication is comple"..., 65Backup and Replication
is complete for mysite.com
) = 65
close(3) = 0
munmap(0x401fd000, 4096) = 0
rt_sigaction(SIGHUP, {SIG_IGN}, {SIG_DFL}, 8) = 0
rt_sigaction(SIGINT, {SIG_IGN}, {SIG_DFL}, 8) = 0
rt_sigaction(SIGQUIT, {SIG_IGN}, {SIG_DFL}, 8) = 0
wait4(3576,
And a ps-ef looks like this.
root 3576 3575 0 02:19 pts/0 00:00:00 tee YourLogFileHere
I have a close (TEE); at the end as well.
Any thoughts?
Thanks
-----Original Message-----
From: Randal L. Schwartz [mailto:merlyn@stonehenge.com]
Sent: Saturday, January 17, 2004 9:55 AM
To: [email]beginners@perl.org[/email]
Subject: Re: Redirect stdout, stderr to file and stdout
Larry> I have a small script that does some admin work for me. What I>>>>> "Larry" == Larry Guest <larry@opsource.net> writes:
Larry> need to do now is not only have is display information to STDERR
Larry> and STDOUT but also write the same information I see when I run
Larry> the command to a file.
Larry> I have written it for others who are not very technical. I want
Larry> them to be able to see the script working and what it is doing.
Larry> But I also need a log file of the same information so I can have
Larry> it mailed to me and keep a copy on the server.
Larry> I cant seem to get this to work.
I think this might do it:
open TEE, "| tee YourLogFileHere";
open STDOUT, ">&TEE";
open STDERR, ">&TEE";
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
0095 <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See
PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!
--
To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
For additional commands, e-mail: [email]beginners-help@perl.org[/email]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Larry Guest Guest
-
Larry Guest #8
RE: Redirect stdout, stderr to file and stdout
I think I have it.
I had to have
close (STDERR)
close (STDOUT)
close (TEE)
-----Original Message-----
From: Larry Guest [mailto:larry@opsource.net]
Sent: Saturday, January 17, 2004 11:22 PM
To: 'Randal L. Schwartz'; [email]beginners@perl.org[/email]
Subject: RE: Redirect stdout, stderr to file and stdout
This is very close.
But the script hangs and wont exit the "tee" command.
I ran the script using "strace" and it sits there like this.
write(1, "Backup and Replication is comple"..., 65Backup and Replication
is complete for mysite.com
) = 65
close(3) = 0
munmap(0x401fd000, 4096) = 0
rt_sigaction(SIGHUP, {SIG_IGN}, {SIG_DFL}, 8) = 0 rt_sigaction(SIGINT,
{SIG_IGN}, {SIG_DFL}, 8) = 0 rt_sigaction(SIGQUIT, {SIG_IGN}, {SIG_DFL},
8) = 0 wait4(3576,
And a ps-ef looks like this.
root 3576 3575 0 02:19 pts/0 00:00:00 tee YourLogFileHere
I have a close (TEE); at the end as well.
Any thoughts?
Thanks
-----Original Message-----
From: Randal L. Schwartz [mailto:merlyn@stonehenge.com]
Sent: Saturday, January 17, 2004 9:55 AM
To: [email]beginners@perl.org[/email]
Subject: Re: Redirect stdout, stderr to file and stdout
Larry> I have a small script that does some admin work for me. What I>>>>> "Larry" == Larry Guest <larry@opsource.net> writes:
Larry> need to do now is not only have is display information to STDERR
Larry> and STDOUT but also write the same information I see when I run
Larry> the command to a file.
Larry> I have written it for others who are not very technical. I want
Larry> them to be able to see the script working and what it is doing.
Larry> But I also need a log file of the same information so I can have
Larry> it mailed to me and keep a copy on the server.
Larry> I cant seem to get this to work.
I think this might do it:
open TEE, "| tee YourLogFileHere";
open STDOUT, ">&TEE";
open STDERR, ">&TEE";
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
0095 <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See
PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!
--
To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
For additional commands, e-mail: [email]beginners-help@perl.org[/email]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
--
To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
For additional commands, e-mail: [email]beginners-help@perl.org[/email]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Larry Guest Guest
-
Jenda Krynicky #9
Re: Redirect stdout, stderr to file and stdout
From: "Larry Guest" <larry@opsource.net>
Strange you only got a few Unix-only solutions when there are at> What I need to do now is not only have is display information to
> STDERR and STDOUT but also write the same information I see when I run
> the command to a file.
least two modules that do this on any OS at all.
See IO::Tee on CPAN or Local::TeeOutput on [url]http://Jenda.Krynicky.cz[/url]
Jenda
===== [email]Jenda@Krynicky.cz[/email] === [url]http://Jenda.Krynicky.cz[/url] =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
Jenda Krynicky Guest



Reply With Quote

