Ruby Language Operating System or Shell commands Clasic ways to execute shell code in Ruby:

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!



exec 'echo "hello world"'


exec ('echo "hello world"')

The System Command:

system 'echo "hello world"'

Will output "hello world" in the command window.


system ('echo "hello world"')

The system command can return a true if the command was successful or nill when not.

result = system 'echo "hello world"'
puts result  # will return a true in the command window

The backticks (`):

echo "hello world" Will output "hello world" in the command window.

You can also catch the result.

result = `echo "hello world"`  
puts "We always code a " + result  


# Will get and return the current date from the system
IO.popen("date") { |f| puts f.gets }

Got any Ruby Language Question?