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
platform.py: _syscmd_file() can't handle target path with space or special shell character #47969
Comments
If you install python in a location which has a space For example $ pwd
/disk0/tmp/foobar(2)/python2.4/bin
$ ./python
Python 2.4.4 (#8, Apr 11 2008, 11:42:39) [C] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> print platform.platform()
sh: syntax error at line 1: `(' unexpected
SunOS-5.10-sun4u-sparc-32bit Note the error from 'sh' was well as the fact that "ELF" The problem is in platform.py: _syscmd_file(target,default='') f = os.popen('file %s 2> /dev/null' % target) This should be: f = os.popen('file "%s" 2> /dev/null' % target) Note the double quotes to protect the path from the shell. I've examined the 2.5, 2.6 and 3.0 source and they all |
Is adding the double-quotes enough to solve the problem ? |
Can you try this patch?
a b/python.exe: MS-DOS executable PE for MS Windows (console) Intel
|
[off topic] Python 2.6b3+ (trunk:66142M, Sep 2 2008, 17:09:46)
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'/home/WhiteRabbit/python-dev/trunk/python' I workarounded this by inserting "target = './python.exe'" in |
Using subprocess is only possible conditionally, ie. if available. We could consider an updated patch for 2.7 and 3.1, but not for 2.6/3.0, I think for 2.6/3.0, adding the extra quotes is enough to get things Please open a new patch ticket for your patch and update it to work with
from _syscmd_file(). I'll checkin the extra quotes. |
Updated the Python versions. |
Well, if python was installed into directory named >>> import platform
>>> platform.architecture()
('32bit', 'ELF') Is it not good to use "file -b" option? |
On 2008-09-02 12:55, Hirokazu Yamamoto wrote:
> Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> added the comment:
>
> Well, if python was installed into directory named
> "foo ELF boo", python will say wrong architecture.
>
>>>> import platform
>>>> platform.architecture()
> ('32bit', 'ELF')
>
> Is it not good to use "file -b" option? Well, I'd say that install path is rather unlikely to occur in real I'm not sure how wide-spread support for the -b option is, so we'd |
Checked in as r66145 and r66146. |
OK, I understand. And I must apologizes about previous fileout = _architecture_split(output)[1:] should not be deleted. It was should be changed to fileout = _architecture_split(output) Thank you. |
To respond to a couple questions: Adding the double quotes fixed the issue I had -- but I did very The "-b" option is not support by 'file' on Solaris. |
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: