1

Hi I would like to execute msbuild in python script

Since I don't run this in visual studio developer command prompt, I run

 "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat"

Then I do

  msbuild example.props

How can I run this in python? I tried to do

 subprocess.call('\"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\\vcvarsall.bat\"\n')

then call

 subprocess.call(['msbuild', filename]) # filename is string variable

but I get an error saying that it coudln't find the file specified.. I am pretty sure there should be a way to do this but I couldn't find how.. Thank you for the help!

4
  • Did it say which file couldn't be found? Commented Jan 25, 2013 at 19:20
  • It said it couldn't find 'msbuild' Commented Jan 25, 2013 at 19:20
  • There was no issue when you called the .bat file? If not, it seems like your environment isn't being updated when you run the .bat file. Try using the shell=True option for call and see if that changes things. Commented Jan 25, 2013 at 19:23
  • I went ahead and put this in an answer so other people may benefit. Glad that worked! Commented Jan 25, 2013 at 19:33

1 Answer 1

1

Because you are not using the shell=True option to call, each call is essentially isolated from each other. Therefore, sourcing the .bat file has no effect on the second call. Add shell=True on both calls so that the first call can effect the second call.

Note: I only recommend shell=True here because it is obvious that this is only being run on one platform (Windows), so there will be no cross-platform issues.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, sorry about bring this up, but for some reason, it's not working. I don't think it's properly shared between calls
I'm on Mac, so I can't see if this works on Windows, but instead of using subprocess.call, try using os.system. This will completely bypass whatever walled garden subprocess.call creates. I have verified that this works on my Mac (I also had troubles with shell=True). It's not elegant, but it seems to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.