Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write STDERR into file

Status
Not open for further replies.

kisan

Programmer
Nov 14, 2002
7
GB
Hi,

Could anyone help me, what is wrong with the program below?
I need to spool the STDERR into a file in order to check it.

Here is the source, which doesn't work:

sub putftp {
$ftp = Net::FTP->new("1.2.3.4", Debug => 1);
$ftp->login("name",'passwd');
$ftp->binary();
$ftp->put($_[0],$_[1]);
$ftp->quit;
close STDERR;
open (STDERR,">>/dir1/dir2/dir3/err.log");
}

Unfortunately, the err.log file always empty.

Thanks,
kisan
 
Kisan, try this.

sub putftp {
close STDERR;
open (STDERR,">>/dir1/dir2/dir3/err.log");
$ftp = Net::FTP->new("1.2.3.4", Debug => 1);
$ftp->login("name",'passwd');
$ftp->binary();
$ftp->put($_[0],$_[1]);
$ftp->quit;
}
Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Hmm, why did you transpose these lines?
Unfortunately it doesn't work either.. :( the log file is empty..

 
you have to redirect STDERR *before* you want to save something to it...

you should also close it again, after doing the thing you need to check

is the ftp operation working? it might be that nothing is being written to STDERR because everything is ok Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
If you are running this program from a command line, try "progname 2> errlog.txt" or "progname > all-log.txt 2>&1"

(And remove your STDERR close and reopen from your code).
The first redirects only STDERR to a file, and the second redirects both STDOUT and STDERR.

Hope this helps,

Pat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top