Introduction to subprocesses and how to use them for everyday use.
Ruby Scripts to Make Life Easier#MakeRubyGreatAgain
View Slide
@PauloAncheta
We make alias-es all thetime. We should makesomething more useful.
# talk.rbsystem “echo hello world”$ ruby talk.rbhello world
# talk*#! bin/env ruby`echo hello world`$ mv talk.rb talk$ chmod u+x talk$ ./talkhello world
# talk*#! bin/env rubystring = “hello world”`echo #{string}`$ ./talkhello world
# talk*#! bin/env rubystring = “hello world”`echo #{string.gsub(/world/,“VanRuby”) } | grep file.txt`$ ./talk | more file.txthello VanRuby
$ irbirb(main):001:0> files = `ls`=>“Applications\nDesktop\nDocuments\nDownloads\nLibrary\nMovies\nMusic\nPictures\nPublic\ntalk\n”irb(main):002:0> files.class=> String
irb(main):003:0> system `ls`=> true
All of that is great. Howcan I be productivedoe?
# clean-pg*#! bin/env rubypg = `ps aux | grep postgres | grep waiting`pg = pg.split(/\n/)pg.each do |waiting|# ... some process to get the pid`kill #{pid}`end
# split-branch*#! bin/env ruby# commits => 1z2y3 TICKET-number msgspecific_commits = `git log - -pretty - -oneline | grep#{ARGV}``git checkout master && git pull origin master && gitcheckout -b test-branch`specific_commits.each do |commit|sha = commit[0..6] # => [123asdf, qwer456, … ]`git cherry-pick #{sha}`end
#MakeRubyGreatAgain