2011-12-30 73 views
0

我有一個與系統命令一起運行的命令。 我可以記錄傳遞給shell的內容嗎?Ruby和系統輸入

P.S.我有與qoutes =

+0

你是什麼意思「什麼是通過」?系統命令返回的結果? – Vapire 2011-12-30 12:56:47

+0

將在shell中調用的確切字符串 – 2011-12-30 13:17:03

+0

是否要捕獲該命令的輸出? – 2011-12-30 14:38:09

回答

1

你提到有「用引號問題」之前,您可以簡單地打印字符串的問題)。我假設你的意思是雙引號?修改Vapire的解決方案:

command = %Q{echo "double quoted string"} # store the command as string 
puts command        # print it before you execute it 
system(command)       # execute it in the shell 
1

你想發送給系統命令

command = "whoami" # store the command as string 
puts command  # print it before you execute it 
system(command)  # execute it in the shell