为什么在我的第二次 exec 调用后 ruby 代码 crash/exit?
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
替换当前的运行ning进程。一旦执行,剩下的部分代码就不是运行.
puts "start"
ret1 = exec('pwd') # <---- After this, no more remaining code is executed.
...
如果要获取命令的输出,请改用Kernel#`
:
puts "start"
ret1 = `pwd`
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
替换当前的运行ning进程。一旦执行,剩下的部分代码就不是运行.
puts "start"
ret1 = exec('pwd') # <---- After this, no more remaining code is executed.
...
如果要获取命令的输出,请改用Kernel#`
:
puts "start"
ret1 = `pwd`