我试图编写一个python脚本,从一个visualstudio2010原生c++项目的mercurial repo中检出一个修订,构建它,然后在各种场景下运行一个程序。然后,我将比较其他构建的结果,等等。因此,我刚开始使用一个原型,我有:
from subprocess import call
import os
import tempfile
import sys
def main():
temp_repo_name = 'temprepo'
d = tempfile.mkdtemp()
os.chdir(os.path.normpath(d))
command1 = ['hg', 'clone', r'C:\temp\1\jxg_hcr', temp_repo_name]
devnull = open(os.devnull,'w')
rc1 = call(command1,stdout=devnull, stderr=devnull)
if rc1 != 0:
print('could not clone repo into temporary directory. Terminating Program')
sys.exit(1)
devnull.close()
devnull = open(os.devnull,'w')
os.chdir(temp_repo_name)
command2 = [r'msbuild', r'hcr_dll.sln', r'/t:Rebuild',r'/p:Configuration=Release']
rc2 = call(command2,stdout=devnull, stderr=devnull)
print rc2
if rc2 != 0:
print('could not build repo. Terminating Program')
sys.exit(1)
devnull.close()
if __name__ == '__main__':
main()
当我运行这个程序时,我在我的控制台上得到以下输出:
^{pr2}$但是当我把命令2改成
rc2 = call(command2)
我明白了
0
<bunch of build output>
0
它成功地建立起来了。我不知道为什么当我重定向时它会失败。在
有什么想法吗?也许只是一个我看不见的愚蠢错误?在
注意:我不认为每次我都需要关闭和重新打开devnull,但这只是我在试图解决问题时尝试的东西。当我一直打开它,最后关闭它时,我得到的结果是一样的。在
编辑1:当我按照davidhess的建议尝试时,这个命令行也失败了。在
EDIT2:我还验证了当我用boiler plate Main函数创建一个空的C#控制台应用程序时,也会出现同样的问题。当msbuild没有重定向到NUL时,它将通过gui在命令行上生成,但是当我重定向时,它返回1而不生成。在
赏金编辑:我最感兴趣的是为什么会这样。显然,我也希望能够默默地成功,如果返回代码为0,只输出一条消息“构建进行得很好”,那么如果没有人能告诉我为什么会发生这种情况,那么奖金将用于最佳解决方案。在
我也尝试了一个bash脚本明蒂.exe公司名称:
#!/bin/bash
for i in 1 2 3 4
do
echo "doing $i"
msbuild.exe /c/temp/$i/jxg_hcr/hcr_dll.sln //t:Rebuild //p:Configuration=Release
echo $?
done
工作(它打印所有输出并成功生成,然后将0打印到控制台),但是
#!/bin/bash
for i in 1 2 3 4
do
echo "doing $i"
msbuild.exe /c/temp/$i/jxg_hcr/hcr_dll.sln //t:Rebuild //p:Configuration=Release > /dev/null
echo $?
done
不执行生成,只向控制台返回1。在
显然这是msbuild中的一个错误: http://connect.microsoft.com/VisualStudio/feedback/details/633122/msbuild-fails-with-1-when-redirecting-the-output-1-nul-2-anywhere
相关问题 更多 >
编程相关推荐