Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

execute shell command without wait? 1

Status
Not open for further replies.

allywilson

Technical User
Nov 27, 2002
157
GB
Hi,
I'm pretty new to using Ruby. As I'm still unfamiliar with of the libraries a lot of the time I just execute a shell command within it (e.g. whatever = `bash command`). This is fine for my purposes usually, but I'm coming across a difficulty whereby I'm unable to commence to the next command within the ruby script without waiting for the first to either timeout or return a result.

I've tried getting around it by introducing an "&" at the end of the shell command (not very good results...), but would rather do it in Ruby itself.

Can anyone advise how?

Any help much appreciated!

Thanks
 
You probably want to look at using threads:
Code:
$ ruby <<EOF
> thread = Thread.new { `sleep 5; echo \"Done.\"` }
> puts "Waiting on the thread..."
> puts thread.value
> EOF
Waiting on the thread...
Done.

Check out the chapter on Threads and Processes in Programming Ruby (as well as the Thread class reference).
 
You sir, are a life saver. That does seem to be the route I need to follow.

Thank you very much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top