Re: Unable to run batch file in CGI Script
by almut (Canon) on Sep 23, 2009 at 12:54 UTC
|
Try system('C:/BatchTest/test.bat') == 0 or print "error: $!\n";
(Update: maybe I should add that if system() fails to
execute the command, it returns -1, and only then $! is
guaranteed to hold a meaningful value... (so testing ... == -1 and print $! would
be the proper way). I suggested to check for a system() return
value of zero, as then it would still print "error:" even in the rare
case that the batch command should execute but not exit with zero (which
typically means an error occurred on the command's side...) )
| [reply] [d/l] [select] |
Re: Unable to run batch file in CGI Script
by VinsWorldcom (Prior) on Sep 23, 2009 at 13:11 UTC
|
It depends on your version of IIS (I'm assuming IIS as you're running Windows Batch files based on your code example). Newer versions of IIS do not allow access to CMD.EXE which is needed to 'interpret' the batch file. This is a new 'security feature' that gave me issues too.
I didn't deal too much with it, just rewrote my batch in Perl, but I understood the only way to get around it was to run the IIS service as "Administrator" - HIGHLY **NOT** RECOMMENDED!!!
| [reply] |
|
|
Hi,
I am using Apache web server.
| [reply] |
|
|
I am stuck with the same problem did u find any solution for this
| [reply] |
Re: Unable to run batch file in CGI Script
by Bloodnok (Vicar) on Sep 23, 2009 at 14:35 UTC
|
Nothing you've written will cause your CGI script to die, hence, assuming your script generates nothing on STDOUT or STDERR, nothing will be output to the browser (via CGI::Carp::fatalsToBrowser). To get a textual representation of any errors, try something like...
my @out = `C:/BatchTest/test.bat`;
die "@out ($?)" if $? != 0;
Check the Apache server logs - they may (or may not;-) provide some indication.
Is Apache configured to 'recognise' the directory containing the target script i.e. C:/BatchTest ?
If so, are the permissions on C:/BatchTest correct ?
A user level that continues to overstate my experience :-))
| [reply] [d/l] [select] |
Re: Unable to run batch file in CGI Script
by marto (Cardinal) on Sep 23, 2009 at 13:09 UTC
|
| [reply] |
Re: Unable to run batch file in CGI Script
by ww (Archbishop) on Sep 24, 2009 at 02:15 UTC
|
"...trying to run a batch file which will start a server through my CGI Script."
Errrr....
What server are you trying to start? What does your batch file look like?
Clearly, you can't start the Apache server if you're using it already. "Restart" maybe, not "start." And if that's the case, the newly re-started Apache isn't going to know your script from a hole in the wall.
| [reply] |
Re: Unable to run batch file in CGI Script
by venkatesan_G02 (Sexton) on Sep 23, 2009 at 13:58 UTC
|
system ('C:/BatchTest/test.vbs') == 0 or print "Error: $!\n";
is returning the following error "Error: No such file or directory".
But when i execute it through command prompt, its executing fine. | [reply] |
|
|
| [reply] [d/l] [select] |
|
|
Yeah. Apache web server is running in the same machine. I even tested the program by placing the batch file in cgi-bin folder and htdocs folder but no use.
| [reply] |
Re: Unable to run batch file in CGI Script
by venkatesan_G02 (Sexton) on Sep 23, 2009 at 15:07 UTC
|
When i use, system('C:/Server/Apache/cgi-bin/test.bat') == -1 or print "Error: $!\n";
The error log file has "Wed Sep 23 20:44:11 2009 error client 4.33.33.177 Wed Sep 23 20:44:11 2009 Run_Another_Prog_from_perl.cgi: Can't spawn "cmd.exe": No such file or directory at C:/Server/Apache/cgi-bin/Run_Another_Prog_from_perl.cgi line 15. ".
I copy and pasted cmd.exe in both htdocs and cgi-bin folder but it's still not working.
| [reply] |
|
|
What version of Windows - Server 2003?
This is *very* similar to the problem I described with IIS - CMD.EXE was not allowed to run by the web server (in my case IIS) even if it resided in the CGI-BIN directory and had proper permissions (everyone - full permissions).
Is this a test system - isolated from the outside world? Try running the Apache service as admin and see if that fixes it - if so, you're experiencing the same issue I was. Obviously running as admin is *NOT* the solution, but it may help diagnose the anomoly you're seeing.
| [reply] |
|
|
Firstly i am having Windows XP. Secondly, i have admin rights in the system and so Apache should also should have admin rights. Thirdly, the system is connected to internet.
| [reply] |
Re: Unable to run batch file in CGI Script
by venkatesan_G02 (Sexton) on Sep 23, 2009 at 16:13 UTC
|
Hi, i finally made the CGI script to open the batch file using
system('C:\\Server\\Apache\\cgi-bin\\test.bat');
The problem now is its printing whatever is written in the batch file but not executing it.
The error log says "Not enough storage is available to process this command.\r "
What does this error mean? | [reply] [d/l] |
|
|
Maybe you can't start a batch file directly, maybe you have to say system('cmd.exe _path_to_batch_file');
| [reply] [d/l] |
|
|
I tried by placing the test.bat file in the C:\Windows\system32 folder and changing thesystem command to "system('cmd.exe test.bat'); but i am getting "Premature ending of headers" error. But the same program is working when executed through command prompt.
| [reply] |