#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    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.
    Plees Help
    Thank's
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,930
    Rep Power
    1225
    What have you tried?

    What errors/warnings are you receiving?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0
    Hi, i use this script but not work , this script is called from my webpage

    #!c:\mrtg\perl\bin\perl.exe -w
    use CGI;
    $parse = new CGI;
    print $parse->header;
    $rc=`C:\\xxx\\xxxxx.bat`;
    print "$rc\n";
  6. #4
  7. 'fie' on me, allege-dly
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2003
    Location
    in da kitchen ...
    Posts
    12,889
    Rep Power
    6444
    The file will need to be in a webserver accessible directory ...
    perl Code:
    $rc=`C:\\xxx\\xxxxx.bat` or die $!;
    --Ax
    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
    Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...
    BIT COINS ANYONE
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0
    I tried , xxxx.bat is not runned on server side, and is displaied in my webpage the patch to xxxx.bat
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,930
    Rep Power
    1225
    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.

    Code:
    #!c:\mrtg\perl\bin\perl.exe
    
    use strict;
    use warnings FATAL => 'all';
    use CGI;
    use CGI::Carp qw(fatalsToBrowser);
    
    my $cgi = CGI->new;
    print $cgi->header;
    
    my $cmd        = 'C:/path/to/some.bat';
    my $cmd_output = `cmd`;
    
    print $cgi->p($cmd_output);
    print $cgi->end_html;

IMN logo majestic logo threadwatch logo seochat tools logo