Skip to content

Instantly share code, notes, and snippets.

@xxd
Forked from SaitoWu/runable.rb
Last active August 29, 2015 13:55
Show Gist options
  • Save xxd/8767543 to your computer and use it in GitHub Desktop.
Save xxd/8767543 to your computer and use it in GitHub Desktop.
#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 }
%x[git init]
matrix.each do |day|
if day == "o"
%x[git commit --allow-empty --author="#{author} <#{email}>" --date="#{date.to_time}" -m"#{date.to_time} - by: #{author}"]
end
date = date.next
end
#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