简体   繁体   中英

How to detect the terminal that is running python?

I've already tried sys.platform, platform.system() and os.name but none of them return something related to cygwin (I always get win32, Windows and nt as output). Maybe because my python was installed on windows (8.1) and not through cygwin. I need to detect if my python file is being executed by cygwin or cmd.

Cygwin uses Linux-style paths; thus you might be able to check the path separator:

import sys
import os.path

def running_cygwin():
    return sys.platform == 'win32' and os.path.sep == '/'

(I don't have a Cygwin here, so this is untested.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM