简体   繁体   English

如何检测正在运行python的终端?

[英]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). 我已经尝试过sys.platform,platform.system()和os.name,但是它们都不返回与cygwin相关的东西(我总是将win32,Windows和nt作为输出)。 Maybe because my python was installed on windows (8.1) and not through cygwin. 也许是因为我的python安装在Windows(8.1)上,而不是通过cygwin安装的。 I need to detect if my python file is being executed by cygwin or cmd. 我需要检测cygwin或cmd是否正在执行我的python文件。

Cygwin uses Linux-style paths; Cygwin使用Linux风格的路径。 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.) (我这里没有Cygwin,因此未经测试。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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