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

I need to portably be able to:

  • Start a process
  • Swallow its output
  • Know if it's still running
  • Kill it
  • Verify that it's dead and gone

    Using fork/exec, kill and waitpid have problems on Windows. IPC::Run and IPC::Open3 deal with spawning and I/O, but don't deal with monitoring and control well. Although an attempt with Open3 solved some spawning issues, either waitpid isn't working or the process isn't dying (perhaps due to pending I/O?).

    I searched perlmonks. The link to STEM gives a blank page. POE seems like overkill (I need to be able to justify inclusion of a package into a corporate distribution). Likewise with Parallel::*.

    Are there any portable approaches I haven't considered, tips to make one of the above approaches work, or should I conditionalize my code to use Win32::Process on Windows?

  • Replies are listed 'Best First'.
    Re: Portable Process Management
    by erroneousBollock (Curate) on Nov 16, 2007 at 07:18 UTC
      I'd love it if someone wrote a "perlish" unified interface for those features. I'd use it all the time.

      Definitely use Win32::Process and related modules... the fork() emulation just presents too many problems.

      -David

    Re: Portable Process Management
    by cdarke (Prior) on Nov 16, 2007 at 09:33 UTC
      Proc::Background Not sure if it meets all your criteria. Might be possible to mod if not.
        This looks promising. Handles everything but the I/O requirement, and that can be addressed with the common redirect syntax that Windows added. Steve
        Have you tried this on Windows Vista? Test 47 is failing in the same way my original code was failing. I'm going to try some older Windows platforms to decide whether it's Vista or my perl build.
    Re: Portable Process Management
    by Anonymous Monk on Nov 16, 2007 at 07:34 UTC
        Know if it's still running
        That perhaps implies that IPC::Run may be inappropriate.

        IPC::Open would definitely be a good place to start.

        -David

          Do you guys mean IPC::Open3? I can't find an IPC::Open on CPAN.