How to tell if you're running on windows?

R

Roy Smith

I'm using 2.5.1. How can I tell if I'm running on windows? The
obvious answer, platform.system(), gets complicated. On the python
that comes with cygwin, it returns 'CYGWIN_NT-5.2-WOW64', but I've got
a native windows build of python where it returns 'Microsoft'.

The real problem I'm trying to solve is whether to build a LIBPATH
environment variable with ';' or ':' delimiting the entries. On the
cygwin build, os.pathsep returns ':', which isn't really correct. If
you use that, you end up building paths that look like c:foo:c:bar.
It should be c:foo;c:bar
 
Z

zeph

I'm using 2.5.1. How can I tell if I'm running on windows? The
obvious answer, platform.system(), gets complicated. On the python
that comes with cygwin, it returns 'CYGWIN_NT-5.2-WOW64', but I've got
a native windows build of python where it returns 'Microsoft'.

The real problem I'm trying to solve is whether to build a LIBPATH
environment variable with ';' or ':' delimiting the entries. On the
cygwin build, os.pathsep returns ':', which isn't really correct. If
you use that, you end up building paths that look like c:foo:c:bar.
It should be c:foo;c:bar

The Cygwin shell uses what appears to be its own pseudo-filesystem. If
you open your Cygwin shell window and type echo $PATH you will see
completely different results from the Windows command shell's PATH env
variable, and you'll see the path sep is indeed ':'.

Cygwin also seems to put drive mount points in /cygdrive/ so you will
have for example "/cygdrive/c/foo:/cygdrive/c/bar" instead of "C:
\foo;C:\bar".

For python *outside* of Cygwin, on Windows, I assume os.path.pathsep
is ';'.

- zeph
 
R

Ross Ridge

Roy Smith said:
The real problem I'm trying to solve is whether to build a LIBPATH
environment variable with ';' or ':' delimiting the entries. On the
cygwin build, os.pathsep returns ':', which isn't really correct. If
you use that, you end up building paths that look like c:foo:c:bar.
It should be c:foo;c:bar

What application is intepretting this LIBPATH environment variable? If
it's another Cygwin app then ":" should be the correct seperator and you
should be building paths that look like "/cygdrive/c/foo:/cygdrive/c/bar".

I normally use the "os.name" variable to detect whether the script is
running on Windows, but the Cygwin version of Python sets it to "posix".
That works for me, since Cygwin tries hard to look like a Unix-type
operating system, my scripts should too. In your case you can use
the "sys.platform" variable to distinguish between Cygwin and a real
Unix-type OS. You may end up needing to treat Cygwin as a special case.

Ross Ridge
 
D

David Robinow

I'm using 2.5.1.  How can I tell if I'm running on windows?  The
obvious answer, platform.system(), gets complicated.  On the python
that comes with cygwin, it returns 'CYGWIN_NT-5.2-WOW64', but I've got
a native windows build of python where it returns 'Microsoft'.

The real problem I'm trying to solve is whether to build a LIBPATH
environment variable with ';' or ':' delimiting the entries.  On the
cygwin build, os.pathsep returns ':', which isn't really correct.  If
you use that, you end up building paths that look like c:foo:c:bar.
It should be c:foo;c:bar

It's not clear to me what you're using LIBPATH for.
Are you running a cygwin executable from Python? Or a Windows
executable from cygwin?
LIBPATH should be in the format desired by the consumer.
 
R

Roy Smith

David Robinow said:
It's not clear to me what you're using LIBPATH for.
Are you running a cygwin executable from Python? Or a Windows
executable from cygwin?

Our build and test environment for windows is cygwin. This is a Python
test script running a native windows executable using subprocess.Popen().
The LIBPATH I'm building is for the executable's environment.

We're looking to possibly replace cygwin with MinGW at some point in the
future. In the past, we've always equated "cygwin" and "windows" in our
build scripts, but now that we're thinking MinGW-ish thoughts, that's
looking like a sub-optimal strategy.
 
R

r0g

Roy said:
I'm using 2.5.1. How can I tell if I'm running on windows? The
obvious answer, platform.system(), gets complicated. On the python
that comes with cygwin, it returns 'CYGWIN_NT-5.2-WOW64', but I've got
a native windows build of python where it returns 'Microsoft'.

The real problem I'm trying to solve is whether to build a LIBPATH
environment variable with ';' or ':' delimiting the entries. On the
cygwin build, os.pathsep returns ':', which isn't really correct. If
you use that, you end up building paths that look like c:foo:c:bar.
It should be c:foo;c:bar


Hi,

Never used cygwin so I have no idea if this will work for you but I have
been using the following...

if getattr(sys, "getwindowsversion", None) is None:
print "Not on Windows, Whoop! :)"
else:
print "Oh dear :-/"


Roger.
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top