Skip to content

Instantly share code, notes, and snippets.

@duobei
Forked from SaitoWu/runable.rb
Created October 16, 2012 14:52
Show Gist options
  • Save duobei/3899762 to your computer and use it in GitHub Desktop.
Save duobei/3899762 to your computer and use it in GitHub Desktop.
exec something on ruby.
#0> non-block call
Thread.new do
blahbla...
end
#1> 4 simple ways to call shell or cmd
`ps aux`
system "ps aux"
exec "ps aux"
%x{ ps aux }
#2> open3 popen & :pid
require 'open3'
Open3.popen2 "ps aux" do |i, o, t|
:pid = t.pid
end
#3> open3 capture & :pid
require 'open3'
o,s = Open3.capture2("ps aux")
:pid = s.pid
#4 Process spawn
:pid = Process.spawn "ps aux"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment