February 19th, 2013, 08:51 AM
How run file.bat with script.cgi on server side
Hi all, i need a script.cgi to run a file.bat from my webpage on the server side.
February 19th, 2013, 09:46 AM
What have you tried?
What errors/warnings are you receiving?
February 20th, 2013, 04:53 AM
Hi, i use this script but not work , this script is called from my webpage
$parse = new CGI;
February 20th, 2013, 06:22 AM
The file will need to be in a webserver accessible directory ...
$rc=`C:\\xxx\\xxxxx.bat` or die $!;
without exception, there is no rule ...
Handmade Irish Jewellery
Targeted Advertising Cookie Optout (TACO) extension for Firefox
The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones
09 F9 11 02
9D 74 E3 5B
D8 41 56 C5
63 56 88 C0
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
-- Jamie Zawinski
- the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...
BIT COINS ANYONE
February 20th, 2013, 08:14 AM
I tried , xxxx.bat is not runned on server side, and is displaied in my webpage the patch to xxxx.bat
February 20th, 2013, 08:50 AM
Use forward slashes in the path instead of the back slashes.
A var name of $rc implies that you want the return code of the command, not its output. So, are you expecting $rc to contain the return code of the bat file or the output that it generates?
EVERY Perl script you write should include the strict and warnings pragmas. Those pragmas will point out lots common mistakes.
While developing cgi scripts, you should add the CGI::Carp module and remove it when the script goes into production.
$parse is not a very good var name for the cgi object. Var names should give an indication of what they hold and/or what they are used for.
It's best practice to not use the indirect object notation (i.e., syntax you used when creating the $parse object).
What happens when you run the bat file from the command line?
Does the user account that the web server is running under have proper permissions to run the bat file?
Add a little vertical and horizontal whitespace to add readability.
use warnings FATAL => 'all';
use CGI::Carp qw(fatalsToBrowser);
my $cgi = CGI->new;
my $cmd = 'C:/path/to/some.bat';
my $cmd_output = `cmd`;