HaTe_87
HaTe_87

Reputation: 11

How to run sudo command/ call python in ruby

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?

Upvotes: 1

Views: 191

Answers (2)

OpenCoderX
OpenCoderX

Reputation: 6318

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?

Upvotes: 0

Sachin Singh
Sachin Singh

Reputation: 7225

try using system method from kernel module

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

Upvotes: 1

Related Questions