Is possible to return after exec cmd?

P

Petr Spisek

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

ollin
 
S

Sean O'Halpin

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
 
M

Markus Prinz

Petr said:
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
 
O

ollin oli

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
 

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

Forum statistics

Threads
474,208
Messages
2,571,082
Members
47,683
Latest member
AustinFairchild

Latest Threads

Top