1

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?

2
  • Is there any reason why running the program as root wouldn't work? Commented May 26, 2013 at 7:21
  • It's not good to run programs as 'root'. What OS are you using? Commented Jun 21, 2013 at 13:41

2 Answers 2

1

try using system method from kernel module

http://www.ruby-doc.org/core-2.0/Kernel.html#method-i-system

Sign up to request clarification or add additional context in comments.

1 Comment

thank you very much, a question: can the called program return a value?
0

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?

3 Comments

with that method am i able to return a value ?
Try using the new link I added
i don't think is my case i have a python program to read from a DS18B20 the temperature... and i need to launch that program and recive the temp.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.