3

I would like to be able to do the following (and it should work on Windows):

  • Run an external command / process
  • Capture all its stdout and stderr (if any)
  • Do this asynchronously (Script must not wait for process to terminate.)
  • "Monitor": When the process terminates, know its exit code
  • "Monitor": If the process doesn't terminate (timeout), being able to terminate said process.
  • I specifically do not need to send anything to this process via stdin

I have to say, I got completely lost between all the stuff under IPC:: ... Open3, Run, Cmd .. oh my ... adding in Capture::Tiny etc. and the caveats mentioned for Win32.

What modules from the Perl "toolbox" are recommended for above? Strawberry Perl 5.14 and up. Any additional CPAN module is OK.

Martin Ba
  • 33,741
  • 27
  • 150
  • 304

1 Answers1

0

On Windows I use ActiveState's ActivePerl.

There is a Win32 interfaces. Take a look at the Win32::Process, I think this could meet some of your requirements for running processes on Windows.

http://docs.activestate.com/activeperl/5.18/lib/Win32/Process.html

You can take a look to other Win32 interfaces

Be careful some CPAN module does not necessary work on Windows, especially when multithreading, forks are involved because it was develop on Unix platforms first.

PS I would be curious if MINGW32 would be a Unix like solution on Windows.

Hope that helps

CrazyRiver
  • 314
  • 2
  • 3
  • [`Win32::Process`](http://search.cpan.org/~jdb/Win32-Process-0.16/Process.pm) is not ActiveState specific. What's *more*, it's rather unclear how STDOUT/ERR piping would work with createprocess. – Martin Ba Aug 14 '14 at 07:54
  • Thank you for the precision and correction. I agree win32::process does not address your requirements on STDOUT and STDERR.It was just a suggestion that could point to a better solution. Some other thoughts, maybe a combination of Perl managing the process and Windows redirection ex.: "some.exe 2>&1 > file.log" See. http://stackoverflow.com/questions/1420965/redirect-stdout-and-stderr-to-a-single-file Have fun! – CrazyRiver Aug 14 '14 at 13:39