in reply to call exe on windows via script

Try separating your command and parameters, (see the docs for the system() call), like this:

system('C:\\perlscripts\\foo.exe', '-c', $color, '-f', $fromNode, '-t' +, $textmsg);
This helps because Perl then takes care of any quoting and shell-escaping needed for your system's shell.

If that fails, you'll want to check the special variables $! and $? (their use for this is explained in the docs for system()). For further debugging, you'll want to post the results, as well as any warnings generated during your run (you are using strict and warnings, right?).

Larry Wall is Yoda: there is no try{}
The Code that can be seen is not the true Code

Replies are listed 'Best First'.
Re^2: call exe on windows via script
by dtharby (Acolyte) on Jul 11, 2005 at 10:54 UTC
    I tried your method but it didn't work.
    I am now getting an exit code of 256 from the system call.

    I am not using strict or warnings. Can I just use warnings and not have to use strict yet ?

    Thanks

      The reason using strict and warnings is useful is that it helps to ensure that the problem you're having is not actually a problem somewhere else in your script. Making your scripts work with both strict and warnings turned on means that if you are still having the same problem, you've isolated it properly. Otherwise you're shooting in the dark a bit.

      Also, it seems as though you didn't read the perlfunc secion on system() as I suggested, or you would have pasted output from a block like this:

      if ($? == -1) { print "failed to execute: $!\n"; } elsif ($? & 127) { printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without'; } else { printf "child exited with value %d\n", $? >> 8; }

      That is a very good and reliable way to find the "real" exit code. It may be that your application is being called correctly, but when called from Perl doesn't have access to the same environment, or a myriad other possibilities. When foo.exe exits, you can read it's docs to find the meaning of that exit code and thereby find the problem.

      However, until your code works with strict and warnings, you are probably just wasting debugging time.

      Larry Wall is Yoda: there is no try{}
      The Code that can be seen is not the true Code
        Thanks for the reply.
        Using my 'debugging' skills, I found the problem without the need for strict and warning on.
        Though I intend to have this in place before the script is used in a production manner.
        Actually I have read numerous articles on the system() command and have found that dividing the error code by 256 gives the true error code.
        However thanks to all who have replied, it has been most helpful.