views:

403

answers:

4

I build a Visual Studio solution from a Python script. Everything works nicely, except that I am unable to capture the build output.

p = subprocess.Popen(['devenv', 'solution.sln', '/build'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = p.communicate()
ret = p.returncode

Here, both out and err are always empty. This happens regardless of the build success as seen in p.returncode.

A: 

That's probably because the software you're running doesn't write to stdout or stderr. Maybe it writes directly to the terminal/console.

If that's the case you'll need some win32 api calls to capture the output.

nosklo
In this case, would I not see the build output on the screen when I run my script?
Gilad Naor
@Gilad: I don't know. Maybe you have to print it back yourself.
nosklo
+1  A: 

You should build the solution with msbuild.exe instead, which is designed to give feedback to stdout and stderr. msbuild.exe is located at

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\msbuild.exe (to build a VS2005 solution) or C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe (to build a VS2008 solution)

Note that msbuild.exe does not take a /build switch like devenv.exe.

Wim Coenen
looks promising, checking it out...
Gilad Naor
A: 

Probably your problem is the same that the pipe's buffer fills up. Check this question for a good answer.

Santi
No, the problem in that case would be a hang, and the solution to is to use p.communicate(). The OP doesn't experience a hang and already uses p.communicate().
Wim Coenen
+2  A: 

Change it from 'devenv' to 'devenv.com'. Apparenty Popen looks for .EXEs first but the shell looks for .COMs first. Switching to 'devenv.com' worked for me.

devenv is significantly faster then msbuild for incremental builds. I just did a build with an up to date project, meaning nothing should happen.

devenv 23 seconds msbuild 55 seconds.

gman