continue the execution of a ruby script after a shell comand

H

Hamlat Ameziane

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 !!!!
 
S

Stefano Crocco

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 =3D '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 =3D Thread.new {exec 'ruby '+path}
Thread.pass (t)

But I have the same result !!!!

=46rom 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 scr=
ipt=20
to go back to. The usual way to run an external program from a ruby script =
is=20
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 stand=
ard=20
output on screen, but returns it as return value of the method call; system=
,=20
instead, displays the standard output normally and returns true if the comm=
and=20
was executed correctly and false otherwise.

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

`ruby #{path}`

I hope this helps

Stefano
 
H

Heesob Park

Hi,

2008/7/17 Hamlat Ameziane said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top