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

Hi, in my windows machine system("any command") , is not triggering the command in turn it returns the return code 65280, and error no such file or directory, when i execute the same command on command prompt it works fine, so can you please help me on this

  • Comment on system command on windows is not executing

Replies are listed 'Best First'.
Re: system command on windows is not executing
by pryrt (Abbot) on Apr 10, 2017 at 14:32 UTC

    As I hinted and you understood in cb, the spawned command returns 255. the issue is with the spawned command. See for example:

    use warnings; use strict; my $s; $s = system q(cat), qw(nosuchfile); printf q(ret=0x%04x, err=>> +%s<<%s), $s, $!, $/; $!=0; $s = system q(xcat), qw(nosuchfile); printf q(ret=0x%04x, err=>> +%s<<%s), $s, $!, $/; $!=0; $s = system q(perl), q(-le), q(exit 0x13); printf q(ret=0x%04x, err=>> +%s<<%s), $s, $!, $/; $!=0; $s = system q(perl), q(-le), q(exit 0xFF); printf q(ret=0x%04x, err=>> +%s<<%s), $s, $!, $/; $!=0;

    (I reset $! every time to make sure it wasn't holding a previous error message)

    cat: nosuchfile: No such file or directory ret=0x0100, err=>><< Can't exec "xcat": No such file or directory at - line 3. ret=0xffffffff, err=>>No such file or directory<< ret=0x1300, err=>><< ret=0xff00, err=>><<

      (For posterity, giving credit to cb solutions): As corion++ mentioned in cb: "Print $^E and $?." (I really should have remembered that one in my example code -- add those to the print lines if you're executing it). And as ambrus++ pointed out, check working directory, use the full path to the command, check for console messages when you system() the command, and be careful with quoting.

      You say it is "not triggering the command". Are you sure that's true, or is the command just exiting early? (My snippet, with the corion-suggested extensions, will give hints as to how far it's being run.)

      Beyond that, if you want further help, you'll need to give more details: a SSCCE will allow us to replicate your results. If the name of the command you're calling in system() is proprietary, you can redact it in your example -- or make an SSCCE that replicates the problem using standard Gnu Linux commands and/or standard Win32 commands.

Re: system command on windows is not executing
by huck (Prior) on Apr 10, 2017 at 15:48 UTC