Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python, subprocess, devenv, why no output?

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.

like image 569
Gilad Naor Avatar asked Oct 06 '09 13:10

Gilad Naor


People also ask

How do I get output to run from subprocess?

To capture the output of the subprocess. run method, use an additional argument named “capture_output=True”. You can individually access stdout and stderr values by using “output. stdout” and “output.

How do you pass a pipe in subprocess?

To use a pipe with the subprocess module, you have to pass shell=True . In your particular case, however, the simple solution is to call subprocess. check_output(('ps', '-A')) and then str. find on the output.

What does subprocess Check_call return?

subprocess. check_call() gets the final return value from the script, and 0 generally means "the script completed successfully".

What does subprocess check call do?

The Python subprocess call() function returns the executed code of the program. If there is no program output, the function will return the code that it executed successfully. It may also raise a CalledProcessError exception.


2 Answers

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.

like image 158
gman Avatar answered Oct 16 '22 10:10

gman


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.

like image 33
Wim Coenen Avatar answered Oct 16 '22 11:10

Wim Coenen