dtharby has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I want to call a windows exe from my perl script but also want to put any error code from the call to a file.

To call the program I know that I have to use the system command :-
system("C:\\Temp\\foobar.exe");
But can I append the .. == 0 or die ... to it and punch this out to a file ?
Thanks
Danny

Replies are listed 'Best First'.
Re: Calling Windows Executable from script
by BrowserUk (Patriarch) on Jun 22, 2005 at 12:18 UTC

    If you mean the exit code of the executable, then you need to print $? >> 8 if the return value from system is non-zero

    system( 'perl -e"exit( 123 )"' ) and print $? >> 8; 123 ## or system( $command ) == 0 or die 'Failed with: ', $? >> 8;

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
Re: Calling Windows Executable from script
by prasadbabu (Prior) on Jun 22, 2005 at 11:19 UTC

    Yes,

    punch this out to a file ?

    system("C:\\Temp\\foobar.exe") || print FOUT "foobar.exe is not present" ;

    Here FOUT is filehandle, to write in a log file.

    updated

    Prasad