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

Hi, smart C programmer, newbie perl programmer.

I just installed apache and perl for win 2k.

Perl seems to work ok, and the apache install seems to work fine, my friend can type in my ip address and everything works great off my tiny dsl connection.

I want to create a perl script that will run a windows exe program I wrote. If I call 'system('d:/myprog.exe')', nothing happens, and the perl script hangs. I can see in the task manager that myprog.exe was started, but I do not see the interface, and nothing is happening.

When I use task manager to try to kill it, permission denied.

I assume this is some sort of problem involing thread or process inheritance or something.

I'M JUST TRYING TO LAUNCH A SILLY WINDOWS PROGRAM.

WHY IS THIS SO DAMN HARD?

And nobody seems to have this problem, I've looked everywhere, can't believe this is not a common problem, oh well.

I installed normal Apache, Im not smartie enough to screw up the default install. I installed normal regular ActivePerl.

YES, a simple perl script seems to work fine, not unless a simple script can work, complicted doesnt, and perl is still screwed. (doubt it)

Is there a problem here with the fact that the program I am trying to launch has a GUI? I have tried using 'cmd.exe', and cmd.exe hangs, cant kill it.

Whats the 'doh!' answer for this! Help!

Edit by tye

Replies are listed 'Best First'.
Re: system() hangs
by seattlejohn (Deacon) on Mar 10, 2002 at 07:07 UTC
    This may be an Apache thing, not a Perl thing (or at least related to the way the two work together). I find I can successfully run this script from the command line:
    system('notepad');

    So apparently the GUI itself isn't a problem. Then again, if I try to run this script via Apache, it hangs as you described.

    A search in Google's Usenet archive turned up old threads (from 1999) about this, and indicate that it occurs for PHP scripts as well as Perl. I didn't see any obvious solutions, but I didn't check every thread either ;-)

Re: system() hangs
by gellyfish (Monsignor) on Mar 10, 2002 at 09:50 UTC

    Is there a problem here with the fact that the program I am trying to launch has a GUI? I have tried using 'cmd.exe', and cmd.exe hangs, cant kill it.

    This is the expected behaviour I'm afraid, when you start a GUI program from a CGI program it is not going to appear on your desktop so you have no way of interacting with it, it is started at the behest of another user in effect and in general one wouldn't want another users programs appearing on your desktop. I can't test this right now but if you are running NT or 2000 then you might be able to alter the configuration of the Apache service so that it has the 'Interact with Desktop' attribute set and change it so it runs under your user but this is almost certainly a very bad thing in security terms ...

    As for cmd.exe you *can* get the output from that to the browser if you do something like:

    print `cmd.exe /c dir`;
    But again I can't test that right now.

    /J\

Re: system() hangs
by jlongino (Parson) on Mar 10, 2002 at 07:46 UTC
    You might want to take a look at this node. I suspect that when you try to run a shell command (via backtics or system) that the process that Perl spawns is butting heads with another process already running in the background. In my case (the node referenced above), it was Norton Antivirus.

    I eventually ran it down by killing unnecessary tasks running in the background and re-running my Perl program. You didn't say what Windows OS you were running, but even if it isn't Win 98, I would still check for this type problem by eliminating unnecessary background applications. I switched antivirus applications and my problem hasn't recurred (I'm using Command Software Antivirus).

    --Jim