从 python 启动 vs2008 构建
第一个批处理文件启动命令提示符,我需要第二个命令位于第一个命令的上下文中。 我怎样才能在Python中做到这一点?
按原样,它启动批处理,并阻塞直到批处理(及其命令提示符上下文)终止,然后在没有必要上下文的情况下执行 devenv。
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')
可以将其想象为我在 bash 中,并且需要在 perl 上下文中执行命令,因此我输入 perl -c 'asdf'
。 连续执行 perl 和 asdf 是行不通的,我需要在 perl 上下文中获取 devenv 。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为实现此目的的正确方法是运行此命令:
下面您将看到同一命令的 Python 版本:
这应该适用于任何 Visual Studio,因此最好编辑问题以使其更详细通用的。
我发现关于 vcvarsall.bat 位置的一个小问题 - 因为 VCINSTALLDIR 并不总是设置,所以您必须使用注册表项才能检测它的安装程序位置:
添加
..\..\ VC\vcvarsall.bat
到此路径。 测试其他版本的 Visual Studio 也是一个好主意。I think that the proper way for achieving this would be running this command:
Below you'll see the Python version of the same command:
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:
Add
..\..\VC\vcvarsall.bat
to this path. Also is a good idea to test for other versions of Visual Studio.在这些情况下,我使用脚本来完成这一切。 这样你就可以随心所欲地链接。 有时我会即时生成脚本。
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.
您可以将 devenv 命令附加到原始批处理文件的末尾,如下所示:(
显然,为了简单起见,我已经缩短了命令)
You could append the devenv command onto the end of the original batch file like so:
(obviously I have shortened the commands for simplicity's sake)
我从设置变量的批处理文件运行 Python 脚本:-)
但 Brett 的解决方案听起来更好。
I run my Python script from a batch file that sets the variables :-)
But Brett's solution sounds better.