[英]why ruby code crash/exit after my second exec call?
puts "start"
ret1 = exec('pwd')
puts ret1
ret2= exec('hostname')
puts ret2
a = "."
puts a
exec('ls ~')
////code exit from here... not any other output why?
puts a
puts a
puts a
我的代碼在第二次調用exec后退出。 這是為什么?
% ruby exec.rb
start
/Users/xxx/code/
這是我運行此代碼時的輸出。
Kernel#exec
替換當前正在運行的進程。 一旦執行,代碼的剩余部分就不會運行。
puts "start"
ret1 = exec('pwd') # <---- After this, no more remaining code is executed.
...
如果要獲取命令的輸出,請使用Kernel#`
代替:
puts "start"
ret1 = `pwd`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.