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

hello all
i have written a code in which it is trying to run qcmd.dat file which runs a tool. while the command executes and provides the required output but an error saying
cant spawn "cmd.exe" at line ......
the tool has many version so qcmd.dat for a version is determined by setting file name provided. please help..thanks in advance

print("Enter y or n to continue with synthesis \n"); my $choice = <STDIN>; chop($choice); if ($choice eq "y") { system (`qcmd.bat $toplevelentity`); } else { print "continue manually with synthesis\n"; }

Replies are listed 'Best First'.
Re: error: can't spawn "cmd.exe"
by Athanasius (Archbishop) on Jul 13, 2015 at 08:13 UTC

    Hello mrityunjaynath,

    To elaborate a little on Anonymous Monk’s answer: the call to `qcmd.bat $toplevelentity` is itself “interpolated and then executed as a system command with /bin/sh or its equivalent.” (perlop) The standard output of this command is then passed to system, which attempts to run this “command” (whatever it is) as another system call. As Anonymous Monk says, you need double quotes (or qq()) here, not backticks (qx()). Alternatively, drop the call to system and just use the backticks:

    if ($choice eq "y") { `qcmd.bat $toplevelentity`; } else {

    But note that, in this case, the (standard) output of the system call will be thrown away, unless you explicitly assign it to a variable or print it. If you call system, standard output goes to the console and only the command’s exit status is returned to the Perl script.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      thanks Athanasius ....your suggestions worked. I have applied ""(double quotes) and everything worked fine.

Re: error:cant spawn "cmd.exe"
by Anonymous Monk on Jul 13, 2015 at 07:52 UTC
    What are this characters `` that you're using, why are you using those instead of double quotes?