This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author dabrahams
Recipients brian.curtin, dabrahams, docs@python, mark, r.david.murray
Date 2010-05-16.14:16:28
SpamBayes Score 0.020597627
Marked as misclassified No
Message-id <1274019390.25.0.838979515547.issue8557@psf.upfronthosting.co.za>
In-reply-to
Content
New data point: in some contexts on Windows (not sure of the exact cause but I was dealing with multiple drives), even this workaround isn't enough.  I ended up having to do something like this (i.e. manually search the path) on win32:


    def full_executable_path(invoked, environ):

        if os.path.splitext(invoked)[1]:
            return invoked
        
        explicit_dir = os.path.dirname(invoked)

        if explicit_dir:
            path = [ explicit_dir ]
        else:
            path = environ.get('PATH').split(os.path.pathsep)

        extensions = environ.get(
            'PATHEXT',
            # Use *something* in case the environment variable is
            # empty.  These come from my machine's defaults
            '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PSC1'
            ).split(os.path.pathsep)

        for dir in path:
            for ext in extensions:
                full_path = os.path.join(dir, invoked+ext)
                if os.path.exists( full_path ):
                    return full_path

        return invoked # Not found; invoking it will likely fail

    class Popen(subprocess.Popen):
        def __init__(
            self, args, bufsize=0, executable=None,
            stdin=None, stdout=None, stderr=None,
            preexec_fn=None, close_fds=False, shell=False, 
            cwd=None, env=None, 
            *args_, **kw):

            if executable is None and not shell:
                executable = full_executable_path(args[0], env or os.environ)

            super(Popen,self).__init__(
                args, bufsize, executable, stdin, stdout, stderr, 
                preexec_fn, close_fds, shell, cwd, env, *args_, **kw)
History
Date User Action Args
2010-05-16 14:16:30dabrahamssetrecipients: + dabrahams, mark, r.david.murray, brian.curtin, docs@python
2010-05-16 14:16:30dabrahamssetmessageid: <1274019390.25.0.838979515547.issue8557@psf.upfronthosting.co.za>
2010-05-16 14:16:28dabrahamslinkissue8557 messages
2010-05-16 14:16:28dabrahamscreate