[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

continue the execution of a ruby script after a shell comand

Hamlat Ameziane

7/17/2008 7:38:00 AM

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-....

3 Answers

Stefano Crocco

7/17/2008 7:47:00 AM

0

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

Heesob Park

7/17/2008 7:50:00 AM

0

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

Hamlat Ameziane

7/17/2008 7:59:00 AM

0

thank you very much !!
it works !!
--
Posted via http://www.ruby-....