Friday, September 18, 2009

Make long multiple system commands in ruby more readable

# Instead of this long line of system command
system "pkill firefox & echo 'To Reboot: #{Time.now}' >> #{log_file} & echo #{PASSWORD} | sudo shutdown -r now"

# Have a readable array of the commands and join them into a string
system [
"pkill firefox",
"echo 'To Reboot: #{Time.now}' >> #{log_file}",
"echo #{PASSWORD} | sudo shutdown -r now"
].join(" & ")

No comments:

Blog Archive