I just started programming in Ruby, I would like to know if you can run a command like "Sudo python XXX.py"
I tried to work with RubyPython, but without success because I do not know how and where is the path of the file to be retrieved.
Does anyone have experience with that?
try using system method from kernel module
http://www.ruby-doc.org/core-2.0/Kernel.html#method-i-system
EDIT: try this
command_output = `sudo python DIRECTORY`
p command_output
Where DIRECTORY is the full path of the script you want to execute.
There are several methods, each with their own differences.
Check out this blog entry: http://alvinalexander.com/blog/post/ruby/how-execute-external-shell-command-expansion
# define your variable
dir='/tmp'
# execute your shell command
puts `ls #{dir}`
EDIT: Check out this stack overflow question: Running a shell command from Ruby: capturing the output while displaying the output?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.