Zach
Zach

Reputation: 19082

How do I create a non-blocking system call in Ruby?

I want to make a system call in ruby, but rather than wait for the process to terminate, I want my script to continue running.

What's the recommended way to handle this?

Upvotes: 4

Views: 2947

Answers (2)

Platinum Azure
Platinum Azure

Reputation: 46193

You can use Process.spawn.

Once the process is spawned, you can either wait for the process to terminate (using waitpid) or detach it.

Upvotes: 10

maerics
maerics

Reputation: 156444

See IO#popen in the standard library.

f = IO.popen("date")
f.gets # => "Wed Aug 10 14:56:59 MDT 2011\n"
f.close

Upvotes: 4

Related Questions