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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:38:53+00:00 2026-06-03T21:38:53+00:00

import subprocess proc = subprocess.Popen(‘git status’) print ‘result: ‘, proc.communicate() I have git in

  • 0
import subprocess

proc = subprocess.Popen('git status')
print 'result: ', proc.communicate()

I have git in my system path, but when I run subprocess like this I get:
WindowsError: [Error 2] The system cannot find the file specified

How can I get subprocess to find git in the system path?

Python 2.6 on Windows XP.

  • 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-06-03T21:38:55+00:00Added an answer on June 3, 2026 at 9:38 pm

    The problem you see here is that the Windows API function CreateProcess, used by subprocess under the hood, doesn’t auto-resolve other executable extensions than .exe. On Windows, the ‘git’ command is really installed as git.cmd. Therefore, you should modify your example to explicitly invoke git.cmd:

    import subprocess
    
    proc = subprocess.Popen('git.cmd status')
    print 'result: ', proc.communicate()
    

    The reason git works when shell==True is that the Windows shell auto-resolves git to git.cmd.

    Eventually, resolve git.cmd yourself:

    import subprocess
    import os.path
    
    def resolve_path(executable):
        if os.path.sep in executable:
            raise ValueError("Invalid filename: %s" % executable)
    
        path = os.environ.get("PATH", "").split(os.pathsep)
        # PATHEXT tells us which extensions an executable may have
        path_exts = os.environ.get("PATHEXT", ".exe;.bat;.cmd").split(";")
        has_ext = os.path.splitext(executable)[1] in path_exts
        if not has_ext:
            exts = path_exts
        else:
            # Don't try to append any extensions
            exts = [""]
    
        for d in path:
            try:
                for ext in exts:
                    exepath = os.path.join(d, executable + ext)
                    if os.access(exepath, os.X_OK):
                        return exepath
            except OSError:
                pass
    
        return None
    
    git = resolve_path("git")
    proc = subprocess.Popen('{0} status'.format(git))
    print 'result: ', proc.communicate()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import os import subprocess proc = subprocess.Popen(['ls','*.bc'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out,err = proc.communicate() print out
Why its not working? :| import subprocess p = subprocess.Popen([rsnmpget,-v,1,-c,public,-Oqv,,-Ln,192.168.1.1 1.3.6.1.2.1.2.2.1.10.7],stdout=subprocess.PIPE).communicate()[0] print p Run
I have the following Python lines: import subprocess subprocess.Popen(egrep -r --exclude=*{.git,.svn}* \text\ ~/directory, stdout=subprocess.PIPE,
Given this : import os import subprocess def check_server(): cl = subprocess.Popen([nmap,10.7.1.71], stdout=subprocess.PIPE) result
I have a problem piping a simple subprocess.Popen. Code: import subprocess cmd = 'cat
import sys sys.path.append('/home/myuser/svn-repos/myproject') from myproject.settings import * But, it says module not found when
import java.lang.Math; public class NewtonIteration { public static void main(String[] args) { System.out.print(rootNofX(2,9)); }
Here is my program import subprocess print Content-type:text/html\r\n\r\n print File starting to execute print
i've got this snazzy python code: import subprocess value = subprocess.Popen([php,./php/php_runner.php],stdout=subprocess.PIPE); the problem is,
Currently I am using this: def _get_mac_ver(): import subprocess p = subprocess.Popen(['sw_vers', '-productVersion'], stdout=subprocess.PIPE)

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.