2

Is there a way to get the command output of the exec task?

exec :checkout do |cmd|
  cmd.command = 'C:/Program Files (x86)/Microsoft Visual Studio 10.0/Common7/IDE/tf.exe'    
  cmd.parameters 'checkout'
end
Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
icn
  • 17,126
  • 39
  • 105
  • 141
  • Do you mean the output of the command or the return code? – knut Dec 21 '11 at 22:10
  • You definitely mean the console output and not the exit code? Because `tf.exe checkout` doesn't produce anything interesting ("No files specified"). Could you say what you want to do with this output so I can help (I maintain Albacore). – Anthony Mastrean Sep 28 '12 at 21:11
  • And how do you want to "get" it? Capture it in a variable? Because `system()` puts it on the console already. If you just need it visible. – Anthony Mastrean Sep 28 '12 at 21:21

1 Answers1

2

You mentioned albacore and you use the task exec. If there is no special need of albacore you may use standard ruby tools:

#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

More solutions may be found at Getting output of system() calls in Ruby

Community
  • 1
  • 1
knut
  • 27,320
  • 6
  • 84
  • 112