1
在我的Ruby脚本中,我调用Perl脚本并等待它完成执行。但是,有时Perl脚本会遇到一系列错误,我希望Ruby能够自动处理这些错误。所以,我采取了以下...在执行过程中停止IO.popen,使用异常情况不佳
begin
IO.popen(cmdLineExecution) do |stream|
stream.each do |line|
puts line
if line =~ /Some line that I know is an error/
raise MyOwnException
end
end
end
begin
#Wait on the child process
Process.waitpid
rescue Errno::ECHILD
end
rescue MyOwnException
#Abort the command mid processing, and handle the error
end
然而,Perl脚本继续工作,即使异常被抛出来执行,只知道它是不是管道输出到STDOUT
了。此时,如果我想停止Perl进程,我必须进入任务管理器并手动停止它。然后Process.waitpid
结束并从那里继续。无论是或者我停止Ruby并且Perl进程继续在后台运行,我仍然必须手动停止它。
BTW:这是Windows
所以因此问题是如何阻止IO.popen没有成为一个孤儿进程中间过程Perl的进程?