Reputation: 21801
The first batch file launches a command prompt, i need the second command to be in the ccontext of the first. how can I do this in python?
As is, it launches the batch, and blocks until the batch (with its command prompt context) terminates, and then executes devenv
without the necessary context.
os.system(r'%comspec% /k ""C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"" x86')
os.system(r'devenv asdf.sln /rebuild Debug /Out last-build.txt')
think of it as in i'm in bash, and i need to execute a command in a perl context, so i type perl -c 'asdf'
. executing perl and asdf back to back won't work, i need to get the devenv
inside of the perl context.
Upvotes: 1
Views: 1126
Reputation: 170628
I think that the proper way for achieving this would be running this command:
%comspec% /C "%VCINSTALLDIR%\vcvarsall.bat" x86 && vcbuild "project.sln"
Below you'll see the Python version of the same command:
os.system('%comspec% /C "%VCINSTALLDIR%\\vcvarsall.bat" x86 && vcbuild "project.sln"')
This should work with any Visual Studio so it would be a good idea to edit the question to make it more generic.
There is a small problem I found regarding the location of vcvarsall.bat - Because VCINSTALLDIR is not always set, you have to use the registry entries in order to detect the location where it is installer:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0]
"InstallDir"="c:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\IDE\\"
Add ..\..\VC\vcvarsall.bat
to this path. Also is a good idea to test for other versions of Visual Studio.
Upvotes: 3
Reputation: 75487
I run my Python script from a batch file that sets the variables :-)
call ...\vcvarsall.bat
c:\python26\python.exe myscript.py
But Brett's solution sounds better.
Upvotes: 2
Reputation: 6426
I these situations I use script that does it all. That way you can chain as much as you want. Sometimes I will generate the script on the fly.
compileit.cmd
call C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat
devenv $1.sln /rebuild Debug /Out last-build.txt
Upvotes: 2
Reputation:
You could append the devenv command onto the end of the original batch file like so:
'%comspec% /k "...vcvarsall.bat" x86 && devenv asdf.sln /rebuild ...'
(obviously I have shortened the commands for simplicity's sake)
Upvotes: 2