从 python 启动 vs2008 构建

发布于 2024-07-07 16:21:16 字数 456 浏览 10 评论 0原文

第一个批处理文件启动命令提示符,我需要第二个命令位于第一个命令的上下文中。 我怎样才能在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

说谎友 2024-07-14 16:21:17

我认为实现此目的的正确方法是运行此命令:

%comspec% /C "%VCINSTALLDIR%\vcvarsall.bat" x86 && vcbuild "project.sln"

下面您将看到同一命令的 Python 版本:

os.system('%comspec% /C "%VCINSTALLDIR%\\vcvarsall.bat" x86 && vcbuild "project.sln"')

这应该适用于任何 Visual Studio,因此最好编辑问题以使其更详细通用的。

我发现关于 vcvarsall.bat 位置的一个小问题 - 因为 VCINSTALLDIR 并不总是设置,所以您必须使用注册表项才能检测它的安装程序位置:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0]
"InstallDir"="c:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\IDE\\"

添加 ..\..\ VC\vcvarsall.bat 到此路径。 测试其他版本的 Visual Studio 也是一个好主意。

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.

丢了幸福的猪 2024-07-14 16:21:17

在这些情况下,我使用脚本来完成这一切。 这样你就可以随心所欲地链接。 有时我会即时生成脚本。

compileit.cmd
  call C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat
  devenv $1.sln /rebuild Debug /Out last-build.txt

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
凝望流年 2024-07-14 16:21:17

您可以将 devenv 命令附加到原始批处理文件的末尾,如下所示:(

'%comspec% /k "...vcvarsall.bat" x86 && devenv asdf.sln /rebuild ...'

显然,为了简单起见,我已经缩短了命令)

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)

单身情人 2024-07-14 16:21:17

我从设置变量的批处理文件运行 Python 脚本:-)

call ...\vcvarsall.bat
c:\python26\python.exe myscript.py

但 Brett 的解决方案听起来更好。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文