in reply to Re: Redirecting errors
in thread Redirecting errors

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

Replies are listed 'Best First'.
Re: Re: Re: Redirecting errors
by Rex(Wrecks) (Curate) on May 09, 2002 at 22:28 UTC
    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!