2013-05-26 212 views
1

sudo命令/調用Python我在Ruby中剛開始編程,我想知道你是否能像 運行命令「須藤蟒蛇XXX.py」如何運行紅寶石

我試着用RubyPython工作,但沒有成功,因爲我不知道如何以及在哪裏獲取文件的路徑。

有沒有人有這方面的經驗?

+0

有什麼理由以root運行是行不通的計劃? – Sirupsen

+0

以「root」身份運行程序並不好。你在使用什麼操作系統? – holaSenor

回答

0

編輯:試試這個

command_output = `sudo python DIRECTORY` 
    p command_output 

其中directory是要執行該腳本的完整路徑。

有幾種方法,每種都有自己的差異。

看看這個博客條目:http://alvinalexander.com/blog/post/ruby/how-execute-external-shell-command-expansion

# define your variable 

dir='/tmp' 

# execute your shell command 

puts `ls #{dir}` 

編輯:看看這個堆棧溢出問題: Running a shell command from Ruby: capturing the output while displaying the output?

+0

用這種方法我能夠返回一個值嗎? –

+0

嘗試使用我添加的新鏈接 – holaSenor

+0

我不認爲是我的情況我有一個Python程序從DS18B20讀取溫度...我需要啓動該程序並收回溫度。 –