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 7666619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:52:45+00:00 2026-05-31T14:52:45+00:00

I am trying to use python to help do some automation around an incremental

  • 0

I am trying to use python to help do some automation around an incremental build function in the Android build system. Generally, from a given directory, I would execute the following command to build whatever is in that directory and subdirectories:

mm -j8

This is analogous to a “make” command, only it is incremental build and is defined as a function in a bash file called envsetup.sh. What is does it not important, just know that it’s a function defined in a bash script somewhere in the file system. To execute this, I can also do:

bash -c ". /path/to/envsetup.sh; mm -j8"

This method of calling it will be important in calling the function from python. I have followed the solution here which shows how to call a function within a bash script from python. I have used this method in a simple script that, in theory, should just spit out the STDOUT and STDERR from executing the command:

import subprocess

command = ['bash', '-c', '. /path/to/envsetup.sh; mm -j8']
(stdout, stderr) = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).communicate()

print 'stdout: ' + stdout
print 'stderr: ' + stderr

The call to Popen, however, never returns. What am I doing wrong that would allow bash to execute the command properly, but Python hangs when executing the command?

  • 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-31T14:52:46+00:00Added an answer on May 31, 2026 at 2:52 pm

    tl; dr:

    Your issue is the use of shell=True. Set it to shell=False and it’ll work.

    With this option set, python will just run the first element of the command array, i.e. bash as a shell script. So currently, python is launching a shell of its own, in order to run your command (bash). It’ll run bash with no arguments, and bash will then wait for input, blocking your python script.

    The shell=True setting is for use cases where you are passing a shell script in as a single string. When you’re explicitly specifying a shell and its parameters as the process to invoke, as you are doing above, you should set shell=False.

    >>> import subprocess
    >>> subprocess.Popen(['bash', 'whatever'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).communicate()
    

    Here’s what the proces tree looks like when I run the above:

      \_ python
          \_ /bin/sh -c bash whatever
              \_ bash
    

    The whatever is actually passed in, but it’s a parameter to the sh, not a parameter to the inner bash, so the command being run is effectively ['/bin/sh', '-c', 'bash', 'whatever'], which is quite different from ['/bin/sh', '-c', 'bash whatever']

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

Sidebar

Related Questions

I am trying to use the help() function in the Python interactive shell to
I'm trying to use Python to download a voice file (mp3) from this site:
I am trying to use Python's ctypes library to access some methods in the
I'm trying to use Python to run pdftotext, but for some reason, my code
I'm trying to use Python 2.7 regex's to retrieve data from sample web pages
I am trying to use python's telnetlib module to get information from a remote
I am getting some unexpected results when trying to use Python Omni Completion on
i'm trying to use the terminal from python VTE binding (python-vte from debian squeeze)
I have some trouble with python. I am trying to get output from a
I'm trying to use django-evolution to modify some models from an existing project. Now

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.