[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Is possible to return after exec cmd?

Petr Spisek

7/11/2006 10:38:00 AM

Hi folks,
why doesn't work command 5.times{exec "pwd"} like this 5.times{puts
"Hello"} ?

ollin

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

3 Answers

Sean O'Halpin

7/11/2006 10:52:00 AM

0

On 7/11/06, Petr Spisek <ollin@email.cz> wrote:
> Hi folks,
> why doesn't work command 5.times{exec "pwd"} like this 5.times{puts
> "Hello"} ?
>
> ollin
>

exec() starts a new process in place of the current one, i.e. the ruby
interpreter. Use system() if you want to launch a child process and
return when it's finished.

Regards,
Sean

Markus Prinz

7/11/2006 10:53:00 AM

0

Petr Spisek wrote:
> Hi folks,
> why doesn't work command 5.times{exec "pwd"} like this 5.times{puts
> "Hello"} ?

Because 'exec' overwrites the current Ruby process, so when 'pwd'
finishes there's nothing left to run. What you are looking for is
'system("pwd")' or "`pwd`".

Greets, Markus

Petr Spisek

7/11/2006 11:24:00 AM

0

Thanks to all,
example 5.times{ system "pwd" } works right.

... I'm beginer with ruby, command system is new sufficient way for me.

thnx

ollin

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