Wait on external program?

Launching external .exe (windows) using:

IO.popen(appname)

I need to wait for that app to finish(close) so I can use its results.

Any help?

Thanks.

···

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

What about using backticks?

result = `appname`

Vale,
Marvin

···

Am 12.09.2010 17:57, schrieb Larry Jones:

Launching external .exe (windows) using:

IO.popen(appname)

I need to wait for that app to finish(close) so I can use its results.

Any help?

Thanks.

Marvin,

Thanks for the suggestion; however, I don’t understand how this will
force Ruby to wait until the external process is complete.

Are you suggesting some sort of while.. loop waiting for the variable to
change?

The external process is not Ruby code but a windows application.

Thanks,
Larry

···

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

The backtick method (yeah, that'a a method, see
http://www.ruby-doc.org/ruby-1.9/classes/Kernel.html#M002609 ) executes
the command you pass, waits for it to finish and captures the output
emmited by the command. I'm on Linux Ubuntu at the moment, but this
example should explain it:

irb(main):001:0> str = `sleep 2; echo hello`
=> "hello\n"
irb(main):002:0>

I use sleep to simulate a long-running operation (well, 2 seconds
lasting :wink: ) followed by outputting hello. The "hello" gets captured by
the backticks method and I assign it to the variable str.

The Kernel#system method is similar to the backticks (it waits for the
process to finish as well), but it doesn't capture the output.

Vale,
Marvin

···

Am 12.09.2010 19:26, schrieb Larry Jones:

Marvin,

Thanks for the suggestion; however, I don’t understand how this will
force Ruby to wait until the external process is complete.

Are you suggesting some sort of while.. loop waiting for the variable to
change?

The external process is not Ruby code but a windows application.

Thanks,
Larry