Home ruby troubleshooting
Post
Cancel

ruby troubleshooting

How to call shell commands from Ruby

cmd = "echo 'hi'" # Sample string that can be used

1
2
wasGood = system( "echo 'hi'" )
wasGood = system( cmd )
1
2
value = %x( echo 'hi' )
value = %x[ #{cmd} ]
1
2
exec( "echo 'hi'" )
exec( cmd ) # Note: this will never be reached because of the line above)
1
2
value = `echo 'hi'`
value = `#{cmd}`

Time

1
Time.new.strftime("%Y%m%d%H%M")
This post is licensed under CC BY 4.0 by the author.