Sunday, August 2, 2009

Help with system command in perl on windows?

If i click Start --%26gt; Run ---%26gt; put in c:\control\x10com32.exe a2 off then click OK, the command executes succesfully.





How would I run this command in a cgi/perl script? I've tried


system ("c:\control\x10com32.exe a2 off"); but nothing happens. Could it be something in a perl configuration that prevents me from launching executables?

Help with system command in perl on windows?
Well, you didn't say which web server you use - IIS or Apache, and which Perl - ActivePerl or Cygwin Perl.


That highly influences possible answer.





First off, replace backslashes by forward slashes - you're feeding the wrong command to it:





system("c:/control/....");





Second, check the exit status right after using this code taken from Perl man page for system().





if ($? == -1) {


print "failed to execute: $!\n";


}elsif ($? %26amp; 127) {


printf "child died with signal %d, %s coredump\n",


($? %26amp; 127), ($? %26amp; 128) ? 'with' : 'without';


} else {


printf "child exited with value %d\n", $? %26gt;%26gt; 8;


}





Check your web server's error log file - it may shed some light on the problem.





Another thing is, if your program x10com32.exe uses GUI, it simply won't work. GUI programs don't work from most Windows-based web servers, because web server runs as Windows service (before any desktop session exists) and Windows prevents services from interacting with desktop. You are limited to command-line programs in that environment.





Replace your command by something more simple - like system("echo great success %26gt; c:/tmp/test.txt");





If that works, but your program doesn't, the problem is in your program.





Good luck.
Reply:This has to do with "quoting" and "control character sequences" in Perl.





Short answer - do this:


system ("c:\\control\\x10com32.exe a2 off");





Long answer:


Read this:


http://www.shlomifish.org/lecture/Perl/N...


No comments:

Post a Comment