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 pekka.klarck
Recipients pekka.klarck
Date 2013-01-24.13:09:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1359032961.6.0.0734607018969.issue17023@psf.upfronthosting.co.za>
In-reply-to
Content
If you add a directory into PATH on Windows so that the directory is in quotes, subprocess does not find executables in it. They are found by the operating system, though, at least when run on the command prompt.

To reproduce:

C:\>python --version
Python 2.7.3
C:\>type test\script.bat
@echo off
echo hello
C:\>set ORIG=%PATH%
C:\>set PATH=%ORIG%;test
C:\>script.bat
hello
C:\>python -c "from subprocess import call; call('script.bat')"
hello
C:\>set PATH=%ORIG%;"test"
C:\>script.bat
hello
C:\>python -c "from subprocess import call; call('script.bat')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Python27\lib\subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "C:\Python27\lib\subprocess.py", line 679, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 896, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified


I don't think you ever need those quotes, even if the directory would have spaces, but it is very confusing that the behavior is different on the command prompt and with subprocess. Additionally, Linux does not suffer from this problem:

$ python --version
Python 2.7.3
$ cat test/script.sh 
#!/bin/sh
echo "hello"
$ PATH=$PATH:test script.sh
hello
$ PATH=$PATH:test python -c "from subprocess import call; call('script.sh')"
hello
$ PATH=$PATH:"test" script.sh
hello
$ PATH=$PATH:"test" python -c "from subprocess import call; call('script.sh')"
hello
History
Date User Action Args
2013-01-24 13:09:21pekka.klarcksetrecipients: + pekka.klarck
2013-01-24 13:09:21pekka.klarcksetmessageid: <1359032961.6.0.0734607018969.issue17023@psf.upfronthosting.co.za>
2013-01-24 13:09:21pekka.klarcklinkissue17023 messages
2013-01-24 13:09:20pekka.klarckcreate