return values of os.system() on win32

Trent Mick trentm at ActiveState.com
Fri Jan 13 20:59:06 CET 2006


[rbt wrote]
> This is a corner case. I'm trying to detect if the py script is running 
> on a 'special' version of windows. I can't go into the details about 
> what makes it unique. Python installs and runs, but the windows API 
> isn't as complete as a normal Windows install... among other things, it 
> doesn't have a winver.exe file, or if it does, it's crippled... this 
> causes os.system('winver') to return a 1... while it returns 0 on 
> Windows XP, etc.

If you just want to check if winver.exe exists you could just try
os.path.exists("path\\to\\winver.exe") if you know where to expect it
(likely "C:\Windows\system32") or you could use which.py:

    >>> import which
    >>> which.which("winver.exe")
    'C:\\WINDOWS\\system32\\winver.exe'
    >>> which.which("nothere")
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
      File "C:\Python24\which.py", line 248, in which
        raise WhichError("Could not find '%s' on the path." % command)
    which.WhichError: Could not find 'nothere' on the path.

http://trentm.com/projects/which/

Trent

-- 
Trent Mick
TrentM at ActiveState.com



More information about the Python-list mailing list