New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test_popen fails on Windows if installed to "Program Files" #43977
Comments
test_popen fails in 2.5c2. The reason is that popen invokes cmd.exe /c "c:\program files\python25\python.exe" -c cmd.exe does not support that syntax, and gives an This problem exists atleast since Python 2.3. To fix this, cmd.exe needs to be invoked as cmd.exe /c "c:\program files\python25\python.exe" -c The attached patch fixes this by always wrapping the It's not clear to me whether this can go into 2.5.1: an |
I don't see a difference between your two command lines here... did you mean to add additional quotes in the second example? |
Indeed, this should read cmd.exe /c ""c:\program files\python25\python.exe" -c "import sys;print sys.argv"" |
I applied the change to: Python 2.6a0 (trunk:58651M, Nov 18 2007, 08:46:54) [MSC v.1400 32 bit and test_popen passes appeared to pass. |
subprocess also needs this fix applied Does the w9xopen command line below not need this? |
What is needed is separate quoting for the command and the argument. "c:\Program Files\Python2.6\Python.exe -u c:\Documents and Settings\Russ It needs to the above as thus: "c:\Program Files\Python2.6\Python.exe" -u "c:\Documents and From the command line, the second case works, but the first doesn't. To make sure that popen works in all cases under windows, test_popen* (yeah, I know, shut up and provide a patch...) |
This has come up recently and Martin's approach seems to work. I updated his patch for trunk, and test_popen passes when I run it with and without a space in the path. Russ Gibson's suggestion was already applied to test_popen, so the only code change is to posixmodule.c. |
Here is a py3k version of the previous patch. os.popen is implemented using subprocess.Popen, so the quoting change was made there. |
It is on Python 2.7a2 >>> os.popen('"C:\\Python27\\python.exe" -c "import sys; print sys.argv" 42').read()
''
>>> os.popen('""C:\\Python27\\python.exe" -c "import sys; print sys.argv" 42"').read()
"['-c', '42']\n"
>>> os.popen3('"C:\\Python27\\python.exe" -c "import sys; print sys.argv" 42')[2].read()
'\'C:\\Python27\\python.exe" -c "import\' est pas reconnu en tant que commande interne ou externe, un programme executable ou un fichier de commandes.\n' It may be related to the test_popen failure. |
Florent is correct. The patch seems to fix regular popen, but popen3 sees problems. I'll see if I can fit this in and have a look. Also of note is that the other flavors of popen are not tested...at least not in Lib/test/test_popen.py or Lib/test/test_os.py |
Is this worth pursuing given the wording here https://docs.python.org/3/library/subprocess.html#replacing-os-popen-os-popen2-os-popen3 ? |
This is fixed for subprocess.Popen in 2.7, 3.1, and 3.2; see bpo-2304. In 2.7, nt.popen still has this problem. As mentioned above, it can be worked around by using subprocess.Popen as described here: https://docs.python.org/2/library/subprocess.html#replacing-os-popen-os-popen2-os-popen3 |
Do we leave this open or close it as there is a known work around for 2.7? |
The docs are pretty clear about using Popen instead of os.popen, and people using popen have likely worked around it already, so we're more likely to break them by changing it now. I vote to close. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: