Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running a Windows executable in a CGI (Perl) script 3

Status
Not open for further replies.

anpfire

Programmer
Oct 8, 2003
22
CA
Hi,
I am running some CGI scripts (written in Perl) on an Apache server, which is on a Windows machine. I am trying to run a Windows EXE file (which takes command-line arguments) within a CGI script, which will be run server-side.
I tried: system("C:/temp/program.exe");
And the browser just keeps loading the webpage (that is created by the CGI script), but never actually loads it. And no errors are reported by the Apache server.
I do not know if this is the right command. But if it is, do you know whether the Apache server needs to be configured to allow EXEs to be run?
I appreciate any help you can give me. Thanks.
 
Sounds like the webpage keeps loading cause it is waiting for data back from the program you started (It is waiting for the finishing of the program). I am not sure but I think there is a difference between backtics and a system call. One is going on as a seperate process and does not interfere with the script and the other one is part of the script so the script will wait untill the program finishes.

So in short it depends on if you need the data created by the program later in the script of not. If you need data from the program you start then in your case the data ain;t comming.

Maybe you could tell us what the program is supposed to do and return?

InDenial

 
The program I'm testing right now is just a simple temporary program I created only to see whether CGI can run it. All it does is create an output file and prints out a sentence in the output file. So it is not looking for any input data. It runs without a problem in the Command Prompt window in Windows.
The program I finally want to use will require input data in the form of command-line arguments, but I'm not testing that right now.
 
If you are printing output to a web browser window then you will need to print the content-type before anything else, and also try playing with buffering '$|' because this can affect how and when text prints.
Code:
print "Content-Type: Text/HTML\n\n";
$| = 1;
also, try using this:
Code:
use CGI::Carp qw(fatalsToBrowser);
this will spit out any errors onto the browser window, which I've found to be extremely handy in the past for debugging. Try putting in some markers in the form of simple 'print' commands, i.e. 'print this at the start of the code' or 'print this at the end of the code'.

Rob Waite
 
system("c:/program/exe"); fires the program and doesn't wait for termination

$rc=`c:/program.exe`; will return the output of the program to the variable $rc.

I'd say the backticks are what you're after.

If you're still experiencing problems post some code

HTH
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ... smack the fecker
 
system(...) ... doesn't wait for termination"

Paul?



Mike

"Deliver me from the bane of civilised life; teddy bear envy."

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

 
I tried $rc=`c:/program.exe`; And that worked. Even with the system and exec command that I was originally trying, it was the backticks that was causing the problem.
Thanks a lot for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top