I would like to run a separate process in Perl (a command line PHP script). I would like to capture this processes output AND return code. Optionally I would like to be able to terminate the process and move on if the process takes longer than N seconds. What should I look into?
相关问题
- How to let a thread communicate with another activ
- $ENV{$variable} in perl
- how to get running process information in java?
- Stop child process when parent process stops
- Why it isn't advised to call the release() met
相关文章
- Does the Linux scheduler prefer to run child proce
- Difference between Thread#run and Thread#wakeup?
- Java/Spring MVC: provide request context to child
- Threading in C# , value types and reference types
- RMI Threads prevent JVM from exiting after main()
- Running a perl script on windows without extension
- Comparing speed of non-matching regexp
- How to start a process in its own process group?
You can use piped open() to get all 3 goals:
This is a frequently asked question. Have a look at this Perl FAQ too. It basically explains the way to run external commands in Perl.
You can try IPC::Run.
Personally, I find the easiest is AnyEvent with AnyEvent::Util::run_cmd and a timer. There is no requirement here to run your entire program under an event loop, I regularly go in and out of the event loops with this solution today. (The following isn't warnings-safe.)
EXIT_ANY
tells capture to allow any exit value; you can instead list allowed ones (capture([0,1,42], ...)
) and capture will throw an exception if another is encountered. By default (if just a command is passed to capture) any non-zero exit value results in an exception.