Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Redirecting errors

by PrimeLord (Pilgrim)
on May 09, 2002 at 20:51 UTC ( [id://165504]=note: print w/replies, xml ) Need Help??


in reply to Redirecting errors

Why are you using system calls to echo information into the files you want? It would be easier to do something like this.
open STDERR, ">> error.txt" or die "$!"; system("identify -verbose $directory\\$DIR[$a] >> c:\\dump.txt") or print STDERR "Error: Error message here";

Replies are listed 'Best First'.
Re: Re: Redirecting errors
by sdyates (Scribe) on May 09, 2002 at 21:36 UTC

    Thanks, I it is always the simple things that are forgotten. I have a follow up though. When I run my script, even when the system command writes to the dump.txt and does not error, the script writes to the STDERR. I did not think this was possible with 'or'

    At this point I believe I have an issue with the command line application. Can an application be in a state where it is both in error and not in error--> my logic tells me this cannot be true. Or tells me this cannot be true--just wondering if there is something about STDERR I am not aware of... after all, I have only been writing perl for a year

    Thanks again,
    sdyates
      It is doing this because your system command is returning 0 (good in Windows but translated as false by Perl) if the command is sucessful and you are not capturing this value. if you do $garbage = system(blah) or "handle error" ; this will return true and things will work like you expect.

      The problem with that is that you will need to evaluate $garbage for a 0 value or die. So:
      $garbage = system("identify -verbose $directory\\$DIR[$a] >> c:\\dump. +txt"); if ($garbage != 0){ system("echo ERROR: $directory\\$DIR[$a] >> c:\\er +ror.txt") ;}
      Also grep's solution is a much better way to go for logging. Cleaner, quicker and not reliant on system() commands.

      "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://165504]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-03-29 06:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found