tags:

views:

97

answers:

1

hi everyone ,

how to find out if the environment is windows or unix . I want to execute such similar code as shown below. Please suggest

import os
if (os.getenv("windows"):
    os.system(cmd/c ...)

if (os.getenv("unix")
    os.system(sh shellscript.sh)

Thanks for all your help.

A: 

Use System.getProperty to get the os.name property.

>>> import java.lang.System
>>> java.lang.System.getProperty('os.name')
u'Mac OS X'
lmz
thanks for the answer , but is there is way to find out whether its windows or unix rather than getting the os-name. Thanks again for your help
kdev
import os and use os.get_os_type(). From what I read in os.py, this will return one of "nt" or "posix".Also: if you want to run something using the shell, use subprocess.Popen with shell=True, it has logic to get the correct command interpreter.
lmz
thanks a lot for your suggestion .
kdev