繁体   English   中英

当我编写一个python脚本来运行配置“Debug | Win32”的Devenv时,它什么也没做

[英]When I write a python script to run Devenv with configure “Debug|Win32” it does nothing

更新:当我使用subprocess.call而不是subprocess.Popen ,问题就解决了 - 有人知道是什么原因造成的吗? 还有另一个问题:我似乎无法找到控制输出的方法......有没有办法将输出从subprocess.call重定向到字符串或类似的东西? 谢谢!

我正在尝试使用Devenv来构建项目,当我在命令提示符下输入它时运行得很好,比如devenv A.sln /build "Debug|Win32" - 但是当我使用python运行它时使用Popen(cmd,shell=true)其中cmd与上面的行相同,它什么也没有显示。 如果我删除| ,只将它改为"Debug" ,它有效....

有人知道为什么会这样吗? 我试图把一\\| ,但仍然没有发生..

这是我正在使用的代码:

from subprocess import Popen, PIPE

cmd = ' "C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\IDE\\devenv" solution.sln /build "Debug|Win32" '

sys.stdout.flush()
p = Popen(cmd,shell=True,stdout=PIPE,stderr=PIPE)
lines = []
for line in p.stdout.readlines():
    lines.append(line)
out = string.join(lines)
print out
if out.strip():
    print out.strip('\n')
    sys.stdout.flush()

...但是,如果我将Debug|Win32Debug交换,它可以正常工作...

感谢这里的每一条评论

devenv.exedevenv.com之间存在差异,两者都是可执行的并且存在于同一目录(叹息)中。 问题中使用的命令行和一些答案没有说出他们想要的,所以我不确定哪个会被使用。

如果你想从命令行调用,那么你需要确保你使用devenv.com ,否则你可能会弹出一个GUI。 我认为这可能是一些(但不是全部)混乱的原因。

见17.1.5.1节。 在python文档中。

在Windows上,Python会自动在项目配置参数周围添加双引号,即Debug | win32作为“Debug | win32”传递给devenv。 您不需要添加双引号,也不需要将shell = True传递给Popen。

使用ProcMon查看传递给devenv的参数字符串。

尝试双引用如:'devenv A.sln / build“Debug | Win32”'

看起来像Windows的shell正在接受那个| 作为管道(尽管有引号和逃逸)。 你试过shell=False吗?

当使用shell = False ,它会将字符串视为单个命令,因此您需要将命令/ arugments作为列表传递..类似于:

from subprocess import Popen, PIPE

cmd = [
    r"C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv", # in raw r"blah" string, you don't need to escape backslashes
    "solution.sln",
    "/build",
    "Debug|Win32"
]

p = Popen(cmd, stdout=PIPE, stderr=PIPE)
out = p.stdout.read() # reads full output into string, including line breaks

print out

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM