Wait on external program?

L

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

Quintus

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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.

What about using backticks?

result = `appname`

Vale,
Marvin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkyM/mIACgkQDYShvwAbcNllKwCgkPK2cNGvicsRoo8IhDJFZU6h
EtMAniELVg9uZ7Bz7Oxy3QUA8WMEfWWy
=ZRwF
-----END PGP SIGNATURE-----
 
L

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
 
Q

Quintus

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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

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 ;-) ) 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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkyNNg8ACgkQDYShvwAbcNnQnwCfRqT+YHMXWv/+2sNdItd42lx+
KkIAnjj6OOc6uLH37Q7rZtjKHc7US+dX
=tpVH
-----END PGP SIGNATURE-----
 

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

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,371
Latest member
Brkaa

Latest Threads

Top