CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
STDERR when perl script is called from a shell script

 



MorayJ
Novice

Sep 28, 2007, 8:13 AM

Post #1 of 4 (212 views)
STDERR when perl script is called from a shell script Can't Post

Hi,

I've done a search for STDERR on the forum and can't find a mention of this question - it is possible it is a non-question.

I have a perl script which is being called from a sed script - although I have die commands in the script, when there is a problem, I can't find a mention of the error in the log to which the sed script writes its errors and noises.

Should I expect my output to turn up in the shell's error log, or is there somewhere else it goes? Is it possible that the sed script has been redirected to a specific place and the perl is writing somewhere else? If I grep for perl in /var/log direcctory, there is no mention of anything perl other than from the xferlog (which is detailing ftp comings and going to a directory called perl).

Can I also ask - Even if you don't use -w, die should still write out shouldn't it?

If there is something weird going on with the setup of the system, is there a way for me to redefine STDERR to my own local error file?

Sorry that it's a bit of a ramble, but it's a bit of a fact-finding query more than a straightforward question.

Thanks for reading.

MorayJ


wgeoghegan
Novice

Oct 6, 2007, 10:33 AM

Post #2 of 4 (208 views)
Re: [MorayJ] STDERR when perl script is called from a shell script [In reply to] Can't Post


Code
open(STDERR, "> error.log"); 
print STDERR "Oops!";
close(STDERR);



(This post was edited by wgeoghegan on Oct 6, 2007, 10:33 AM)


MorayJ
Novice

Oct 7, 2007, 4:28 AM

Post #3 of 4 (198 views)
Re: [wgeoghegan] STDERR when perl script is called from a shell script [In reply to] Can't Post

Thanks for the reply and it maybe helps me with my clarity.

Here is a script:
_____________________________________
#!/usr/bin/perl

open (STDERR, ">error.log");


open FILE,">/root/nofile.txt" || die "Can not open file for writing\n";


print STDERR "Oops!";
______________________________________

Now, as far as I am aware, I can not write to the root directory (touching a file there is denied). So when I run the above script, I would expect the die to print to the error.log file. All I get though is "Oops!".

There is something missing which I can't quite put my finger on....


MorayJ
Novice

Oct 7, 2007, 9:53 AM

Post #4 of 4 (196 views)
Re: [MorayJ] STDERR when perl script is called from a shell script [In reply to] Can't Post

Hi,

Thanks again for your help wgeoghegan. It gave me cause to look at the problem I was having as coming from a different area. Your code works fine: what was not working was my code where I was using "||" for 'or', which I believe I have always done. But it looks like I should be using or for 'or' otherwise it gets ignored.

Live and learn..

Cheers
Moray

PS (EDIT)
Or I could write (which I presumably was doing when I was using a book to do perl):


Code
open (FILE,">/root/nofile.txt") || die "Can not open file for writing\n";

I've bracketed FILE....txt"
The removal of any ambiguity gives || back its power


(This post was edited by MorayJ on Oct 7, 2007, 9:57 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives