http://www.perlmonks.org?node_id=401230

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

I am trying to make a script that will execute a program on my web server. I tried using exec and system but it just hangs the script up and nothing happens. I am running the script through the webserver and the server is windows (not my choice). Any help would be great.

Replies are listed 'Best First'.
Re: executing a program
by tall_man (Parson) on Oct 21, 2004 at 18:00 UTC
    I think you would do better to use a module like IPC::Run, which can launch processes on both Windows and Linux using the native APIs of each. Fork is not supported well, if at all, on Windows.

    You might want to think about sending a signal to a daemon process running on the side. Creating child processes in the web server directly will imply little control over waiting for them to finish.

      i have no clue what you mean by daemon adn child processes. I'm totally lost. Anyone know some docs i can read to understand all this.
        Is this web server under your control, or are you using a web server administered by someone else? In the latter case, my suggestion of running a daemon process (which just means a program running on the system outside the web server program) won't work unless you can persuade the administrator to set it up for you.
Re: executing a program
by Zaxo (Archbishop) on Oct 21, 2004 at 17:36 UTC

    fork is the canonical way to launch a second process in a very controlled way. YMMV on winders; IIS and win32 my have some strangeness lurking. Test well.

    After Compline,
    Zaxo

Re: executing a program
by AcidHawk (Vicar) on Oct 22, 2004 at 07:13 UTC
    Hi,

    We really need more info.

  • Are you looking for the output of the program you are trying to run to be displayed in the webpage?
  • Is the program you are trying to run a perl script or an exe?
  • Can you use a FORM with method="POST" action="yourprog.pl" ?
  • Can you use Win32::Process or Win32::Spawn to launch you prog?
    -----
    Of all the things I've lost in my life, its my mind I miss the most.
      You guys have all been realy realy good help. To asnwer a few questions, I have no clue what a deamon process is and I do have access to the webserver, it's in my room. To answer AcidHawk's question,

    • No, I am not looking for the output in the webpage.
    • The program is a perl script.
    • I could us a form with method post, but i don't know what that would accomplish since i'm not sending data to the perl script and I want the perl script to run even when i close the webpage.
    • I will take a look at Win32::Process and Win32::Spawn and see, but I don't know why I couldn't. I just don't know what they are.
        Posting code that you think is not working also helps us find issues quickly..

        Could it be that you need to specify the perl binary before the script.. ie

        exec("C:/Perl/bin/perl.exe myscript.pl");
        -----
        Of all the things I've lost in my life, its my mind I miss the most.