I need to check if my Python script is running inside the Windows Terminal (as opposed to the CMD.exe, Powershell, bash, etc.).
How can this be done?
I need to check if my Python script is running inside the Windows Terminal (as opposed to the CMD.exe, Powershell, bash, etc.).
How can this be done?
I have created a package for this problem: https://pypi.org/project/AssertWT/
import assertwt
assertwt.is_wt() # True,False
The source code for the is_wt method can be found on github
you can get the parent process id (PID) for the process that run/spawned and run your python script and search in the tasklist in windows CMD and see this pid belongs to whom:
In you python script add those lines
import psutil
my_father_pid = str(psutil.Process().ppid())
print my_father_pid # or print(my_father_pid) in python3
Now search for 'my_father_pid` that you have get, in the task list:
tasklist /v | findstr "<my_father_pid>"