Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Running a .exe file in perl/cgi in windows 2000 server

by hamibab (Initiate)
on Dec 07, 2004 at 05:52 UTC ( #412831=perlquestion: print w/replies, xml ) Need Help??

hamibab has asked for the wisdom of the Perl Monks concerning the following question:

I have a cgi file written in perl in which I try to execute an .exe file, e.g. notepad.exe I want to run this cgi file by Internet Explorer in Windows 2000 server. The cgi file and notepad.exe are both saved in wwwroot/inetpub/myfolder, but when I put adress http://localhost/myfolder/myfile.cgi in IE, it halts trying to open the file. By the way, I have installed perl and set .cgi files to be opened by perl. The problem cant be with the syntax of the code since the cgi file is run fine from the commandline using the perl command: perl myfile.cgi and the notepad is executed. But with IE the problem arises However, if I omit that notepad.exe commad line, I can run the cgi file from IE without problem. So runnig the .exe file causes the problem I did set the permissions (reading, writing,code executing) in Internet service manager.

My perl code:

#!c:/perl/bin/perl # print "Content-type: text/html\n\n"; print"Hi!"; `notepad`;

Edited by davido: Added code tags and formatting, per consideration.

Replies are listed 'Best First'.
Re: Running a .exe file in perl/cgi in windows 2000 server
by saskaqueer (Friar) on Dec 07, 2004 at 06:21 UTC

    It is not a permissions problem. Since IE hangs while trying to access the CGI file, it is clear that the system call to notepad.exe is indeed working. If you check the list of programs running under the 'Processes' tab of the Windows Task Manager while accessing the CGI, I'm confident you will see notepad.exe listed. Since notepad does not exit until the user exits it intentionally, the 'hanging' you are experiencing is notepad waiting for the user to exit notepad.

    External programs you execute while within a CGI script are run hidden -- you will not see the graphical interface for the program; in this case, the notepad window. I'm wondering whether you are expecting the notepad window to appear on the server computer that is running the CGI process, or if you're wanting notepad to run on the client's computer.

    If you are looking to have the notepad program run on the server side, then the best method I can think of is to have the CGI script add a command to a database to execute (such as 'notepad.exe'), and then write a separate server-type script that will execute these commands outisde the CGI server process. If you're expecting notepad to run on the client's side, you'd have to have the client download the program first.

      I wanna firstly thank you for your reply. Actually that .exe file is not notepad.exe . The whole thing belongs to a web-based program that does some kind of online simulation. The program used to be on Apache server and worked fine. Now I am trying to trasfer it on Windows server. But I came across the problem of processing the cgi files in Windows. That exe file is acutally a simulation exe file which reads some data from another txt file and do some calculation and make another output txt file. So the whole thing would be run on the server side, not client side. The user (client) "submit" some data in a html page which will run the cgi file. The cgi file put the submitted data in a txt file, and then calls the exe file and redirect to another html page which would contain the results of simulation. I have problem running that exe file under windows server! if I run the cgi file in the commandline (perl myfile.cgi), everthing works OK and that output is made. However, from IE , it halts in spite of the fact that the related "process" is called( as I checked in the "processor" tab.)
        Hi, I am facing a similar problem, did you find a solution to this? If yes, can you let me know? Thanks a ton. Karan (
Re: Running a .exe file in perl/cgi in windows 2000 server
by sgifford (Prior) on Dec 07, 2004 at 06:18 UTC
    Remember that a CGI script runs on the Web server, so if you succeeded, every time a client visited myfile.cgi a copy of Notepad would pop up on the server. I suspect this isn't what you want, and making Notepad run on the client's computer from a regular Web page isn't possible; it would be a security risk. You'd have to use ActiveX or Java and really loosen the security settings to allow this.

    If you do want this to start up on the server, I believe the problem is the display, though I'm no Windows expert. IIS doesn't have permission to open up windows on the display of the currently logged-in user, so interactive programs like Notepad can't work, but non-interactive programs should work OK.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://412831]
Approved by Old_Gray_Bear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2021-04-21 12:28 GMT
Find Nodes?
    Voting Booth?

    No recent polls found