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.

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

Am 12.09.2010 17:57, schrieb Larry J.:

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

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

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

Am 12.09.2010 19:26, schrieb Larry J.:

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 :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
-----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-----

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs