2011-12-21 49 views
2

有沒有辦法獲得exec任務的命令輸出?如何從Albacore exec任務獲取命令輸出?

exec :checkout do |cmd| 
    cmd.command = 'C:/Program Files (x86)/Microsoft Visual Studio 10.0/Common7/IDE/tf.exe'  
    cmd.parameters 'checkout' 
end 
+0

找到你的意思是命令或返回代碼的輸出是什麼? – knut 2011-12-21 22:10:50

+0

命令的輸出 – icn 2011-12-21 23:07:03

+0

你一定是指控制檯輸出而不是退出代碼?因爲'tf.exe checkout'不會產生任何有趣的內容(「沒有指定文件」)。你能說出你想用這個輸出做什麼,所以我可以幫助(我維護Albacore)。 – 2012-09-28 21:11:28

回答

2

您提到了albacore,並且您使用任務exec。如果沒有特別的需要長鰭金槍魚的你可以使用標準的Ruby工具:

#Define the command: 
cmd = 'dir' 
#or in your case: 
#cmd ['"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\tf.exe"', 
#  'checkout'].join(' ') 


#Version one: 
output = `#{cmd}` 
puts output 

#Version two: 
output = %x{#{cmd}} 
puts output 

更多的解決方案,可以在Getting output of system() calls in Ruby

相關問題