Is there a way to check if my python script is running in Windows Command Prompt, vs Cygwin? Using os.name
doesn't work because Cygwin on Windows still returns "nt". I want to check the command prompt's name or type from a shell script so I can differentiate between Command Prompt and Cygwin.
Asked
Active
Viewed 1,769 times
1

gusg21
- 147
- 11
-
Maybe the perl version is not exactly the same. – simlev Mar 15 '17 at 21:57
-
What do you mean? – gusg21 Mar 15 '17 at 22:04
-
Ops, I mean Python: Cygwin installs its own python executable, so scripts running inside a Cygwin terminal will probably use that. What python executable is used by your scripts running inside a Windows command prompt? If you make them use a different one, possibly a slightly different version, you could check the version and know which environment you are in. – simlev Mar 15 '17 at 22:09
-
Possible duplicate of [How can I know if my python script is running? (using Cygwin or Windows shell)](http://stackoverflow.com/questions/22571333/how-can-i-know-if-my-python-script-is-running-using-cygwin-or-windows-shell) – Taku Mar 15 '17 at 22:15
-
1My copy of Cygwin uses my Windows' Python. And I don't just want to detect Cygwin, I want to detect specifically Windows Command Prompt. – gusg21 Mar 15 '17 at 23:27
-
My suggestion is to **create** a difference you can detect. Either **make** the script use a slightly different Python version, or create a file before launching the script as abccd suggests, or simply call the script with an additional parameter, e.g. w from cmd and c from cygwin. I can't think of any drawbacks. – simlev Mar 16 '17 at 05:11
-
But I want this to work universally. The user shouldn't have to do anything besides run it. If it's just not possible, I'm OK with that. – gusg21 Mar 16 '17 at 12:38
1 Answers
2
Have you tried
import platform
platform.system()
On my system it outputs
CYGWIN_NT-10.0
Hope this helps

jayaram S
- 580
- 6
- 13
-
actually this works better `from sys import platform as _platform` `_platform == "cygwin"` – jayaram S May 17 '17 at 15:05
-
Thank you! I solved the problem another way, but this works exactly like I wanted. – gusg21 May 21 '17 at 12:43