How do I call shell commands in Ruby?
cmd = "echo "hi"" # Sample string that can be used
value = `echo "hi"`
value = `#{cmd}`
value = %x( echo "hi" )
value = %x[ #{cmd} ]
wasGood = system( "echo "hi"" )
wasGood = system( cmd )
exec( "echo "hi"" )
exec( cmd ) # Note: this will never be reached because of the line above
$?.exitstatus
Source: By CodingWithoutComments as answer to the question
This code snippet was collected from stackoverflow, and is licensed under CC BY-SA 4.0
Related code-snippets:
- When to use lambda and Proc.new?
- What is the best way to fix 'Unprocessed view path found' error with ExceptionNotifier plugin in rails 2.1?
- How can I modify a.xfdl file?
- How can I reverse DNS for Ruby?
- In Ruby, I can map multiple arrays and values from one array to the other.
- How do you run a Rake task?
- What are the pros and cons of using MySQL instead of SQLite for Rails web development?
- How do I update Ruby Gems from behind a proxy (ISA-NTLM)?
- How do I create a class using Singleton Design Pattern in Ruby?
- Date arithmetic in Unix shell scripts.
- How can we resolve symbolic links in a shell script?
- Why doesn't Ruby have a StringBuffer?
- How do I write a command line program?
- Ruby mixins and calling super methods. Ruby calls and super methods, Ruby calls and Ruby mixins and calls super methods. Ruby calls and super methods.
- Drawing Library for Ruby.