`exec`杀死脚本

时间:2014-02-13 15:40:23

标签: ruby exec

通过sdiff运行exec会导致我的脚本无错误地退出。即使是确保块也无法运行:

begin
  puts "I occur"
  exec("sdiff onefile.csv anotherfile.csv > filediffs.txt")
rescue Exception => e
  puts "I do not get printed"
  puts e
ensure
  puts "I do not get printed"
end
puts "I used to get printed, repeatedly, now not, repeatedly"

它按预期工作了一段时间,然后它开始神秘地退出,条件是相同的。 “我发生”后没有终端输出。

2 个答案:

答案 0 :(得分:1)

这是exec方法的预期行为,documentation表示:

  

通过运行给定的外部命令

替换当前进程

您可能希望使用system代替exec

答案 1 :(得分:1)

exec将通过作为参数传递的命令替换当前进程。执行exec()后,调用进程将不再存在。

检查this以获取参考和替代方案。

相关问题