How To Open A Powershell Terminal With One Python Script?
Solution 1:
It's possible for one Python script to spawn another that will run in parallel with it via subprocess
. The spawned process can then display any text piped to it (via normal print
statements or calls) in a simple tkinter
-based window -- see the errorwindow
module in this answer of mine for more information.
It likely doesn't matter how the original script gets started. I personally have used it both in ones that were started from a command shell as well as from other tkinter
based applications -- so starting yours from powershell should be fine. The module's original author was using Linux or something similar, I believe.
Solution 2:
You should convert your second program to .exe first,the one will display user commands. Say you saved it as usercommands.exe
, after then in your main script use this to open that;
import subprocess
subprocess.Popen([r"usercommands.exe"],
creationflags=subprocess.CREATE_NEW_CONSOLE)
It'll open another console window that runs usercommands.exe
when you run your main file.
Notes;
They must be in the same directory, your main file and .exe file
usercommands.exe
must show the commands in an infinite loop(while True
), so it's going to display commands untill the user close it.
Edit;
Now, we have some spells and usercommands
will have to use that spell variables after then show us some combinations. For doing this, we have to import your first file to usercommands
script.It's going to like this;
usercommands.py
import mainfile #mainfile.pyif choose == mainfile.wizard:
print (something)
if choose == mainfile.subzero:
print (something)
The algorithm should be like this,you will convert usercommands.py
to .exe then it will work as you want I guess, we can't now before you try it ;)
Post a Comment for "How To Open A Powershell Terminal With One Python Script?"