Launch external program

Hi all,

I’m running external programs like this:

  status = `rdesktop .... &`

But my ruby script doesn’t work until the external program finished.
How can I run an external program asynchronously?

Thanks.

system(“command”)

You cannot save the output, though.

Hi,

Am Mittwoch, 17. Jun 2009, 22:22:49 +0900 schrieb Christopher Carver:

You cannot save the output, though.
Yes, you can.

output = “”
t = Thread.new { output << somecmd }

t.alive? or puts “The full output is:”, output

Bertram

On 17.06.2009 16:02, Bertram S. wrote:

Am Mittwoch, 17. Jun 2009, 22:22:49 +0900 schrieb Christopher Carver:

On Wed, Jun 17, 2009 at 8:08 AM, Andrey D. [email protected]wrote:

I’m running external programs like this:

 status = `rdesktop .... &`

But my ruby script doesn’t work until the external program finished.
How can I run an external program asynchronously?

system(“command”)

Christopher, system does not execute commands asynchronously.

You cannot save the output, though.

Yes, you can.

Obama? :slight_smile:

output = “”
t = Thread.new { output << somecmd }

t.alive? or puts “The full output is:”, output

You can do this as well:

t = Thread.new { somecmd }

output = t.value

It seems Thread#value is rarely used but it can be of very useful.

Kind regards

robert

Robert K. wrote:

output = t.value
Thread#value blocks while the thread is running, though.

Joel VanderWerf wrote:

Robert K. wrote:

output = t.value
Thread#value blocks while the thread is running, though.

Ok but how would you in Windows start a seperate program like a vendor
software that runs seperate from the ruby program? If I try
run_me.exe or
system(“run_me.exe”) the ruby program just sits waiting for the other to
finsh?

2009/6/17 Joel VanderWerf [email protected]:

t = Thread.new { somecmd }

output = t.value

Thread#value blocks while the thread is running, though.

Well, yes. But what is your point? If you want the result you need
to wait anyway. If not you can still use your pattern:

t.alive? or puts “The full output is:”, t.value

Kind regards

robert

Hi,

Am Donnerstag, 18. Jun 2009, 05:45:08 +0900 schrieb Robert K.:

output = t.value
Gosh, that’s the programming style I was looking for.

Bertram