Do read the above links, they are good. Do you want to wait for that .bat file to finish before your script continues, or do you want the script to carry on once it starts the .bat. If the latter, what should happen if the script finishes before the .bat it launched? Here is some totally untested code to give you some ideas

use strict; # Always start a Perl script with these two without the +m use warnings; # there are many subtle ways to shoot yourself in the f +oot use CGI; # Load the module to handle CGI stuff my $cgi = CGI->new(); # get a CGI object. # Point to the batfile, notice we can use / as a path separator in Per +l # even when we are in a Windows world. my $batfile = 'c:/program files/mycode/batman.bat'; # I guess you are going to get the parameter from the CGI invocation my $param = $cgi->param('some_field'); # run the command and wait for it to complete. Catch STDERR my $result = `$batfile $param 2>&1`; # This probably won't work as we did not set up an http header, you ma +y want # to use logfile, send output to the cgi invoker, or just throw it aw +ay Print "the command: $batfile $param\nGasve the result: $result";

This code will be saved in your cgi-bin and invoked with a url like:

http://yourserver/cgi-bin/thiscode.pl?some_field=fieldOfDreams

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

In reply to Re: How do I execute a bat file from cgi script? by Random_Walk
in thread How do I execute a bat file from cgi script? by btpoole

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.