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.
In reply to non-blocking backticks by chris212
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |