classification
Title: platform.architecture() prints bogus message on windows
Type: Stage:
Components: Library (Lib) Versions: Python 3.0
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, lemburg, ocean-city
Priority: normal Keywords: patch

Created on 2008-09-01 11:42 by ocean-city, last changed 2008-09-02 10:29 by ocean-city. This issue is now closed.

Files
File name Uploaded Description Edit
fix.patch ocean-city, 2008-09-01 12:50
Messages (8)
msg72227 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2008-09-01 11:42
As title, platform.architecture() prints vogus messege.

>>> import platform
>>> platform.architecture()
指定されたパスが見つかりません。
('32bit', 'WindowsPE')

It says "speicied path is not found".
msg72230 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2008-09-01 12:03
This difference between trunk and py3k would go down to this.

import os
os.popen(r'file e:\python-dev\py3k\PC\VC6\python_d.exe 2> /dev/null')

trunk prints nothing, but py3k prints that message.

I don't know which is popen's correct behavior, we can supress this
message by using subprocess.Popen instead.

Index: Lib/platform.py
===================================================================
--- Lib/platform.py     (revision 66090)
+++ Lib/platform.py     (working copy)
@@ -110,7 +110,7 @@

 __version__ = '1.0.6'

-import sys, os, re
+import sys, os, re, subprocess

 ### Platform specific APIs

@@ -942,7 +942,7 @@
     """
     target = _follow_symlinks(target)
     try:
-        f = os.popen('file %s 2> /dev/null' % target)
+        f = subprocess.Popen('file %s 2> /dev/null' % target,
stdout=subprocess
.PIPE, stderr=subprocess.PIPE).stdout
     except (AttributeError,os.error):
         return default
     output = f.read().strip()
msg72231 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-09-01 12:27
The call to _syscmd_file() should be avoided on windows platforms:
- the "file" program does not exist
- the stderr is redirected to /dev/null, which does not necessarily exists!

On my machine, there is a "c:\dev" directory. Now it contains a file
named "null", which content is "'file' is not recognized as an internal
or external command, operable program or batch file."
No comment.
msg72233 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2008-09-01 12:30
I think it's better to disable that function in the same way as done for
_syscmd_uname:

    if sys.platform in ('dos','win32','win16','os2'):
        # XXX Others too ?
        return default

BTW: I assume you are running this on win32, right ?
msg72234 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2008-09-01 12:50
I've attached patch. (trunk)

>BTW: I assume you are running this on win32, right ?

Yes, I'm running win2k.
msg72246 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2008-09-01 14:08
Looks good. Could you apply it to both trunk and the py3k branch ?!

Mark it "Reviewed by Marc-Andre Lemburg" to keep folks happy ;-)
msg72255 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2008-09-01 14:36
Thanks, fixed in r66104(trunk) and r66106(py3k)
msg72323 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2008-09-02 10:29
Well, should I backport this to release25-maint branch?
(If accepted, issue3719 as well)
History
Date User Action Args
2008-09-02 10:29:13ocean-citysetmessages: + msg72323
2008-09-01 14:36:12ocean-citysetstatus: open -> closed
resolution: fixed
messages: + msg72255
2008-09-01 14:08:13lemburgsetmessages: + msg72246
2008-09-01 12:50:05ocean-citysetfiles: + fix.patch
assignee: lemburg ->
messages: + msg72234
keywords: + patch
versions: - Python 2.6
2008-09-01 12:31:16lemburgsetassignee: lemburg
2008-09-01 12:30:00lemburgsetnosy: + lemburg
title: [py3k] platform.architecture() prints vogus messege on windows -> platform.architecture() prints bogus message on windows
messages: + msg72233
versions: + Python 2.6
2008-09-01 12:27:44amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg72231
2008-09-01 12:03:07ocean-citysetmessages: + msg72230
2008-09-01 11:42:48ocean-citycreate