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

Fellow monks,

I have this piece of code that respawns CruiseControl.net on our project build server :
#!/usr/bin/perl -w use strict; use warnings; use Win32; my (@ccnet, $ccpid, $cwd); # --- Grep ccnet.exe pid @ccnet = split(/\n/,`C:\\systools\\\@SI\\PsTools\\pslist.exe`); @ccnet = grep(/ccnet/, @ccnet); $#ccnet and print "@ccnet\n"; ($ccpid) = "@ccnet" =~ /ccnet\s+(\d+)\s+/; # --- Kill ccnet.exe, if it exists if ( ! $ccpid ) { warn "NO ccnet\n"; } else { print "found ccnet (pid:$ccpid)\n"; kill('HUP', $ccpid); print "killed ccnet.exe (pid:$ccpid)\n"; sleep(3); } # --- Respawn ccnet.exe print "respawning ccnet.exe\n"; $ENV{SSDIR} = '\\Blr11e\kmd.sdpi.ews1'; $cwd = Win32::SetCwd("C:\\Program Files\\CruiseControl.NET\\server" +) || die "$!"; exec("start ccnet.exe") or print "couldn't exec ccnet: $!";
The code does as expected when run from a cmd-window on Windows (starts a new window and execs ccnet.exe in this window).
However...

When I execute this code from my perl cgi.script :
# Run ResetCCN.pl (exec overlay, - don't wait for new ccnet!) sub respawn_CCNet { print "<hr><h4>Restarting CCNet, -- please WAIT</h4><pre>"; system("perl ResetCCN.pl"); sleep(10); print "</pre><br>DONE!<hr>"; }
it respawns the ccnet process in the background (it's alive and visible in the process list), BUT it is not running (as i want it to) in a cmd window...

I've browsed the several Win32 modules for process control on Windows, but can't seem to find any suitable way to accomplish what I want.

Any pointers here...??
Best regards,
Allan Dystrup

Replies are listed 'Best First'.
Re: CGI and spawning a process with UI (Win32)
by shmem (Chancellor) on Apr 14, 2007 at 19:00 UTC
    Any pointers here...??
    • the process which spawns ccnet.exe is running under which account?
    • is that the same account under which the windows GUI session is running?

    Perhaps if you logged in at the console with the account which your web server is running under, you would see the proces in a cmd window?

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      Hi shmem,

      The cgi process (doing: system("perl ResetCCN.pl");) is running under the same logon account (and running the exact same code: ResetCCN.pl) as when ResetCCN.pl is run directly from a command-line window.

      Can it be that a system/exec from a program initiated from a CGI-program (ie the IIS webserver) will pr. default start the process in the background? And how might that be tweaked to run the program with a proper UI ?

      Allan
        The cgi process (doing: system("perl ResetCCN.pl");) is running under the same logon account (and running the exact same code: ResetCCN.pl) as when ResetCCN.pl is run directly from a command-line window.

        Sure? so the IIS Webserver is running under that account, and not under e.g. "Local System" ?

        --shmem

        _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                      /\_¯/(q    /
        ----------------------------  \__(m.====·.(_("always off the crowd"))."·
        ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: CGI and spawning a process with UI (Win32)
by cdarke (Prior) on Apr 15, 2007 at 14:05 UTC
    Try using Win32:Process:Create and setting the flag CREATE_NEW_CONSOLE.
      That sounds like a good idea; -- I've searched for a ppm, but found none. Are you aware of a ppm repository with a Win32::Process distribution?
      Best regards -- Allan