How to tell if you're running on windows?

Discussion in 'Python' started by Roy Smith, Dec 4, 2009.

  1. Roy Smith

    Roy Smith Guest

    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
     
    Roy Smith, Dec 4, 2009
    #1
    1. Advertising

  2. Roy Smith

    zeph Guest

    On Dec 4, 10:46 am, Roy Smith <> wrote:
    > 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
     
    zeph, Dec 4, 2009
    #2
    1. Advertising

  3. Roy Smith

    Ross Ridge Guest

    Roy Smith <> wrote:
    >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

    --
    l/ // Ross Ridge -- The Great HTMU
    [oo][oo]
    -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/
    db //
     
    Ross Ridge, Dec 4, 2009
    #3
  4. On Fri, Dec 4, 2009 at 1:46 PM, Roy Smith <> wrote:
    > 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.
     
    David Robinow, Dec 4, 2009
    #4
  5. Roy Smith

    Roy Smith Guest

    In article <>,
    David Robinow <> wrote:

    > On Fri, Dec 4, 2009 at 1:46 PM, Roy Smith <> wrote:
    > > 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?


    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.

    > LIBPATH should be in the format desired by the consumer.
     
    Roy Smith, Dec 4, 2009
    #5
  6. Roy Smith

    r0g Guest

    Roy Smith wrote:
    > 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.
     
    r0g, Dec 5, 2009
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Miguel Dias Moura
    Replies:
    2
    Views:
    342
    Martin
    Jun 22, 2004
  2. yogesh
    Replies:
    1
    Views:
    367
    Victor Bazarov
    Mar 14, 2007
  3. alex23
    Replies:
    4
    Views:
    233
    Asun Friere
    Jul 16, 2009
  4. winter heat
    Replies:
    0
    Views:
    101
    winter heat
    Nov 1, 2010
  5. Mike A
    Replies:
    17
    Views:
    263
    Dr John Stockton
    Nov 19, 2003
Loading...

Share This Page