Q:

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

My this code exit after second call of exec. Why is that?
% ruby exec.rb
start
/Users/xxx/code/

This is my output when I ran this code.

A:

Kernel#exec replaces the current running process. Once it's executed, the remaining part of the code is not run.
puts "start"
ret1 = exec('pwd')  # <---- After this, no more remaining code is executed.
...

If you want to get the output of the command, use Kernel#` instead:
puts "start"
ret1 = `pwd`

