Stefano Crocco
7/17/2008 7:47:00 AM
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 =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