return values of os.system() on win32

R

rbt

Is it safe to say that any value returned by os.system() other than 0 is
an error?

if os.system('winver') != 0:
print "Winver failed!"
else:
print "Winver Worked."

Thanks!
 
J

Jorge Godoy

rbt said:
Is it safe to say that any value returned by os.system() other than 0 is an
error?

I believe not. That depends on the return/error code of the specific program
you ran.

--
Jorge Godoy <[email protected]>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
 
P

Peter Hansen

rbt said:
Is it safe to say that any value returned by os.system() other than 0 is
an error?

if os.system('winver') != 0:
print "Winver failed!"
else:
print "Winver Worked."

According to the docs, assuming that *in general* would be an error, but
it's likely that for the sorts of cases you are talking about, it's true.

Ultimately, since the return code is generally under the control of the
application you're calling, it's absolutely possible (likely) that there
are many programs which do not work as you assume above, and probably a
large number which don't ever explicitly set the return value at all...

-Peter
 
R

rbt

Peter said:
According to the docs, assuming that *in general* would be an error, but
it's likely that for the sorts of cases you are talking about, it's true.

Ultimately, since the return code is generally under the control of the
application you're calling, it's absolutely possible (likely) that there
are many programs which do not work as you assume above, and probably a
large number which don't ever explicitly set the return value at all...

-Peter

OK, thanks guys. That's helpful... this is more of an MS issue than a
Python issue.
 
P

Paul Watson

rbt said:
Is it safe to say that any value returned by os.system() other than 0 is
an error?

if os.system('winver') != 0:
print "Winver failed!"
else:
print "Winver Worked."

Thanks!

What are you really seeking to do? Are you wanting to detect if your
code is running on a Windows machine? Are you wanting to know the
version number of Windows? Why not use popen2() and see the output?
 
R

rbt

Paul said:
What are you really seeking to do?

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.
 
T

Trent Mick

[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:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,276
Messages
2,571,384
Members
48,073
Latest member
ImogenePal

Latest Threads

Top