473,405 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

return values of os.system() on win32

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!
Jan 13 '06 #1
6 2842
rbt <rb*@athop1.ath.vt.edu> writes:
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 <go***@ieee.org>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
Jan 13 '06 #2
rbt wrote:
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

Jan 13 '06 #3
rbt
Peter Hansen wrote:
rbt wrote:
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


OK, thanks guys. That's helpful... this is more of an MS issue than a
Python issue.
Jan 13 '06 #4
rbt wrote:
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?
Jan 13 '06 #5
rbt
Paul Watson wrote:
rbt wrote:
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?


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

Jan 13 '06 #6
[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
Tr****@ActiveState.com
Jan 13 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mike Kearl | last post by:
I want to set the local Date Time of the xp systems in my organization using C# and a winform application. From what I have read this is not an easy task anymore. You have to obtain privlege...
3
by: Sean | last post by:
Hi, I would like to know all the available values for Message.Msg, Message.LParam, Message.WParam. Where can I find all the values? (complete information) In the .NET documentation, it says...
9
by: WithPit | last post by:
I am trying to create an Managed C++ Wrapper around an unmanaged library which contains C++ code. Some of the unmanaged methods returns an returntype which is of the abstract base type (for...
3
by: Sarah | last post by:
I have a function residing in a module that is doing some file copy and database query operations. This function is called from a regular form under a System.Windows.Forms.Timer control. The...
4
by: Nikolay Petrov | last post by:
Does anyone know where I can find the Windows API's return codes? I know they are in platform SDK, but I wonder isn't there other place where I can find them, because I don't wish to download the...
1
by: Ratz | last post by:
Hello everyone! I'm new to this Forum! I've spent about 56 hours trying to solve a .NET VB Runtime error while Using a program.Ive contacted the developer of the program and he could not figure out...
0
by: Lambuz | last post by:
Hi all, I've got this problem. I've to implemente a solution like the example in http://support.microsoft.com/default.aspx?scid=kb;EN-US;313891, but I can't configure correctly the example. ...
37
by: Army1987 | last post by:
Is that in the object line a conforming program? If so, why? If not, why? I'd expect it to be much like int main(void) { for (;;); } But if I compile it with lcc-win32 and run it in its...
6
BezerkRogue
by: BezerkRogue | last post by:
I am new to software development. I am trying to launch a client side script that will read the values of HKLM\SYSTEM\ControlSet001\Control\ComputerName. The script give me the following error when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.