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

We are using a set of external binaries on Windows to, roughly speaking, control a job management system. For this discussion it is sufficient to know that there exists a bkill.exe, which can be used from the Windows command line to kill a job:

bkill.exe 4711
kills the job with number 4711. If this job has already terminated at the time of killing, we get not surprisingly the message
Job <4711>: Job has already finished

on standard error. Now comes the funny thing: When I call the program from Perl, say with
perl -lwe "system(qq(bkill 4711))"
I get the following answer under ActiveState Perl 5.10:
Job <4711>: Job has already finished Can't spawn "bkill.exe 4711": No error at -e line 1.
Even without knowing anything about the internals of bkill.exe, I wonder why this error is displayed (after all, it obviously *could* spawn bkill.exe), and why this is considered as "No error".

Since I also happen to have Perl 5.7 installed, I tried it with this version too, and here, the output looks even funnier:

Job <4711>: Job has already finished Job <4711>: Job has already finished Can't spawn "cmd.exe": No such file or directory at -e line 1.
This gives some hint: Maybe Perl 5.7 thought too that it could not spawn the process, but maybe - different to 5.10 - retries once until giving up.

The problem does not appear so far with any other program (and also with bkill only in this certain circumstance - for instance, "killing" a job which has never existed, or killing an existing job, does not show any unusual output). Now of course we have no oddities what is going on within bkill - I don't have the source code -, but no matter what it is, how could possibly be Perl tricked into thinking that it could not spawn the process?

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re: What error is "No Error"
by almut (Canon) on Nov 03, 2008 at 15:02 UTC

    Just a guess, but maybe bkill is returning a negative exit code in case of "Job has already finished", which might then indirectly trigger this warning from win32.c:

    if (status < 0) { if (ckWARN(WARN_EXEC)) Perl_warner(aTHX_ packWARN(WARN_EXEC), "Can't spawn \"%s\": %s +", argv[0], strerror(errno)); status = 255 * 256; }

    The reason (errno) is presumably just a random value left over from some previous error...

    (status is the return value of win32_spawnvp(), so to really understand what's going on, one would have to take a closer look to figure out what exactly that routine is returning under what circumstances... (which I haven't done yet))

      maybe bkill is returning a negative exit code

      This makes sense! Thanks a lot!

      -- 
      Ronald Fischer <ynnor@mm.st>
Re: What error is "No Error"
by ig (Vicar) on Nov 03, 2008 at 16:04 UTC
Re: What error is "No Error"
by Krambambuli (Curate) on Nov 03, 2008 at 15:04 UTC
    The error message you got seems actually OK:

    Can't spawn "bkill.exe 4711": No error at -e line 1.

    Note that it is "bkill.exe 4711" - do you have a "bkill.exe 4711".exe in reach ? :) You probably need qw instead of qq,
    perl -lwe "system(qw(bkill 4711))"

    Krambambuli
    ---

      Nice idea, but it does not work out. Aside from the fact that it would imply a serious bug in Perl's system("...") (which is a function so frequently used that it would have been noticed earlier - note that the argument to system *is* allowed to be a string representing a whole command line), it would not explain why the error occurs only for processes which have been finished. Aside of this, we can see from the previous output line that bkill *was* executed correctly, before the error message was displayed. So I guess almut's guess comes closer to the real explanation...

      -- 
      Ronald Fischer <ynnor@mm.st>
        You're right, my first thought is clearly wrong. I should also have paid attention to the fact that 'bkill 4711' becomes "bkill.exe 4711" in the error message, which makes it clear that the system understood which program to call.

        Sorry - it was meant to help, even if it didn't.

        On the bright sight, it made me check 'perldoc -f system' once more :)

        Krambambuli
        ---