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

Hi, I have following line in my Perl code--> system("start my.exe myfile.ext") == 0 or die "error ($?) : $!"; Q1: How do I close my.exe? Q2: If I give myfile.ex1 instead of myfile.ext, myfile fails to open. However, the error code returned by Perl is still 0. Normally (when I specify myfile.ext), if I check what is stored in $!, its always "No such file or directory". I want to report the error while opening 'myfile'. How can it be done? Thanks.

Replies are listed 'Best First'.
Re: Close EXE & die command
by roboticus (Chancellor) on Jan 05, 2010 at 12:16 UTC

    pbhandari:

    I think the problem is that you're using start to run your program. So perl is getting the result of start rather than the result of your my.exe program.

    ...roboticus

Re: Close EXE & die command
by mykl (Monk) on Jan 05, 2010 at 13:16 UTC

    I surmise that you're running on Windows: in that case you may find that Win32::Process provides more useful tools than system(), if you want to monitor the state of your external executable or terminate it early.

    --

    "Any sufficiently analyzed magic is indistinguishable from science" - Agatha Heterodyne