1

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.

7
  • Maybe the perl version is not exactly the same. Commented Mar 15, 2017 at 21:57
  • What do you mean? Commented Mar 15, 2017 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. Commented Mar 15, 2017 at 22:09
  • Possible duplicate of How can I know if my python script is running? (using Cygwin or Windows shell) Commented Mar 15, 2017 at 22:15
  • 1
    My copy of Cygwin uses my Windows' Python. And I don't just want to detect Cygwin, I want to detect specifically Windows Command Prompt. Commented Mar 15, 2017 at 23:27

1 Answer 1

2

Have you tried

import platform
platform.system()

On my system it outputs

CYGWIN_NT-10.0

Hope this helps

Sign up to request clarification or add additional context in comments.

2 Comments

actually this works better from sys import platform as _platform _platform == "cygwin"
Thank you! I solved the problem another way, but this works exactly like I wanted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.