Continue the execution of a ruby script after a shell comand

Hi,
I have a little problem,I will be grateful if someone can help me.

So I have this script :

puts '*** Beginning of the script ***'
path = 'C:\another_script.rb'
exec 'ruby '+path
puts '*** End of the script ***'

And I have the following result :

puts '*** Beginning of the script ***'
## execution of script C:\another_script.rb

But Ruby dont print the last line : *** End of the script ***

I have tried this :

t = Thread.new {exec 'ruby '+path}
Thread.pass (t)

But I have the same result !!!!

···

--
Posted via http://www.ruby-forum.com/.

From ri for Kernel#exec:

"Replaces the current process by running the given external command."

This means that when the external program stops, there's no more a ruby script
to go back to. The usual way to run an external program from a ruby script is
to use either the backtics operator:

`ruby C:\another_script.rb`

or to use Kernel#system:

system "ruby C:\another_script.rb"

The difference between the two is that the former doesn't display the standard
output on screen, but returns it as return value of the method call; system,
instead, displays the standard output normally and returns true if the command
was executed correctly and false otherwise.

Note that the backtics support string interpolation, so you can write:

`ruby #{path}`

I hope this helps

Stefano

···

On Thursday 17 July 2008, Hamlat Ameziane wrote:

Hi,
I have a little problem,I will be grateful if someone can help me.

So I have this script :

puts '*** Beginning of the script ***'
path = 'C:\another_script.rb'
exec 'ruby '+path
puts '*** End of the script ***'

And I have the following result :

puts '*** Beginning of the script ***'
## execution of script C:\another_script.rb

But Ruby dont print the last line : *** End of the script ***

I have tried this :

t = Thread.new {exec 'ruby '+path}
Thread.pass (t)

But I have the same result !!!!

Hi,

···

2008/7/17 Hamlat Ameziane <ameziane.hamlat@etu.univ-nantes.fr>:

Hi,
I have a little problem,I will be grateful if someone can help me.

So I have this script :

puts '*** Beginning of the script ***'
path = 'C:\another_script.rb'
exec 'ruby '+path
puts '*** End of the script ***'

And I have the following result :

puts '*** Beginning of the script ***'
## execution of script C:\another_script.rb

But Ruby dont print the last line : *** End of the script ***

I have tried this :

t = Thread.new {exec 'ruby '+path}
Thread.pass (t)

But I have the same result !!!!

You shoud use system method instead of exec in this case.

Regards,

Park Heesob

thank you very much !!
it works !!

···

--
Posted via http://www.ruby-forum.com/.