chris212 has asked for the wisdom of the Perl Monks concerning the following question:
Is there a thread-safe and cross-platform way to capture output from a command but kill the command if it takes too long to run? This would be easy to do with IPC::Run, but that doesn't seem to be thread-safe on Windows. Capturing output is easy with backticks, but that will block until the command completes. Maybe I could start a watcher thread which will watch for a child process to be created and kill that child process if it is still running after the timeout expires. Maybe use a semaphore or something to ensure the new child process found is from the same thread that started the watcher. But that would be less than ideal. I could use devfs on Linux, but I'm not sure how I would identify the child process in Windows. Maybe call pslist or powershell, or maybe there is a CPAN module I can load at runtime only for Windows. Any better ideas?
EDIT:Maybe I'm going about this wrong. I could create a small Perl wrapper script that uses IPC::Run and executes the passed command with a timeout.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: non-blocking backticks
by bliako (Abbot) on Mar 26, 2019 at 20:49 UTC | |
by chris212 (Scribe) on Mar 26, 2019 at 21:58 UTC | |
by bliako (Abbot) on Mar 26, 2019 at 23:07 UTC | |
by stevieb (Canon) on Mar 26, 2019 at 22:15 UTC |