Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6947925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:45:19+00:00 2026-05-27T13:45:19+00:00

I am trying to write a python script that checks out a revision from

  • 0

I am trying to write a python script that checks out a revision from a mercurial repo for a visual studio 2010 native c++ project, builds it, and then runs a program under various scenarios. Then I will compare results from other builds, etc. So I am just getting started with a prototype, and I have:

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()

When I run this, I get the following output on my console:

C:\programming\eclipse_workspace\hcr_cli_build>python hcr_cli_build.py
0
1
could not build repo.  Terminating Program

But when I change the line for command2 to

rc2 = call(command2)

I get

0
<bunch of build output>
0

and it builds successfully. I do not know why it would fail when I redirect.

Any Ideas? Maybe just a silly error I cannot see?

NOTE: I don’t think I really need to close and re-open devnull each time, but it was just something I was trying out when I was trying to figure out the issue. I get the same results when I just keep it open the whole time and close it at the very end.

EDIT1: This also fails from the command line when I tried it per the suggestion of David Hess.

EDIT2: I have also verified this same issue occurs when I create an empty C# console application with the boiler plate Main function. It will build via the gui and on the command line when msbuild is not redirected to NUL, but when I do redirect, it returns 1 and does not build.

Bounty Edit: I am most interested in why this is happening. Obviously, I would also like to be able to succeed silently and just output a message saying “Build went okay” if the return code was 0, so if nobody can tell me why it is happening, the bounty will go to the best solution.

I also tried a bash script on mintty.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

works (it prints all the output and builds successfully and then prints 0 to the console), but

#!/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

does not perform the build and just returns 1 to the console.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:45:20+00:00Added an answer on May 27, 2026 at 1:45 pm

    Apparently this is a bug in msbuild:
    http://connect.microsoft.com/VisualStudio/feedback/details/633122/msbuild-fails-with-1-when-redirecting-the-output-1-nul-2-anywhere

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a python script that does the following from within a
I'm trying to write a small Python script that will get query results from
I am trying to write out a python cgi script that will redirect me
I'm trying to write a python script that packages our software. This script needs
I am trying to write a python script that takes record data like this
I am trying to write a Python script that will access and modify the
I'm trying to write a simple Python script that inserts .odt documents into an
I am trying to write a python script that will SSH to a server
I'm trying to write a python script that modifies the contents of <script> tag
In the process of trying to write a Python script that uses PIL today,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.