Let’s say I have some terminal commands like:
sudo mycommand1
mycommand2
#.....
What should I do run them via ruby script (not bash) in Ubuntu?
UPDATE:
I have a ruby script:
def my_method1()
#calculating something.....
end
def method2(var1, var2)
#how do I sudo mycommand1 and any other Lunix command from here?
end
def method3(var4)
#calculating something2....
end
You can do
system,exec, or place the command in backticks.exec("mycommand")will replace the current process so that’s really only pratical at the end of your ruby script.system("mycommand")will create a new process and return true if the command succeeded and nil otherwise.If you need to use the output of your command in your Ruby script use backticks: