I'm writing a ruby script and found this strange behaviour.
Using ruby 2.4.2 [x86_64-darwin16]
Basically I'm trying to echo two separated messages and in my index.rb
file I got:
exec("echo 'teste'")
exec("echo 'teste2'")
But when I run ruby ./index.rb
The output is:
teste
Why that's happening?
Shouldn't this be the output?
testeteste2
exec([env,] command... [,options])
Replaces the current process by running the given external command docs
It means that the first call to exec
replaces your ruby program with echo
, so the rest of the ruby program is not executed.
You can use backticks to run a command like you want:
`echo 'teste'`
`echo 'teste2'`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With