Is possible to return after exec cmd?

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

ollin

On 7/11/06, Petr S. [email protected] 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

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

On 7/11/06, Petr S. [email protected] wrote:

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

Because exec (as in the shell BTW) replaces your process with the
program
passed as argument. That is the ruby interpreter is replaced by pwd.
What you want is probably system
5.times{ system “pwd” }

Cheers
Robert

ollin


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


Deux choses sont infinies : l’univers et la bêtise humaine ; en ce qui
concerne l’univers, je n’en ai pas acquis la certitude absolue.

  • Albert Einstein

fr ollin:

why doesn’t work command 5.times{exec “pwd”} like this 5.times{puts

“Hello”} ?

since that is exec’s feature. exec replaces current process.

maybe you want system or `

irb(main):004:0> echo am still here
=> “am still here\n”
irb(main):005:0> system “echo am still here”
am still here
=> true

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

since that is exec’s feature. exec replaces current process.

maybe you want system or `

irb(main):004:0> echo am still here

=> “am still here\n”

irb(main):005:0> system “echo am still here”

am still here

=> true

ok, ok, if you really want to run exec, you can do something this
stupid,

irb(main):012:0> ruby -e "exec 'pwd'"
=> “/root\n”
irb(main):014:0> system %q[ruby -e “exec ‘pwd’”]
/root
=> true

On Jul 11, 2006, at 7:00 AM, Peña, Botp wrote:

ok, ok, if you really want to run exec, you can do something this
stupid,

irb(main):012:0> ruby -e "exec 'pwd'"
=> “/root\n”
irb(main):014:0> system %q[ruby -e “exec ‘pwd’”]
/root
=> true

That’s an impressively longwinded approach. I applaud you, sir :slight_smile:
-Mat