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的進程?