Reputation: 105
I want to just print some information and call an application e.g. notepad.
from subprocess import call
print("Opening Notepad++")
call([r"C:\Program Files (x86)\Notepad++\notepad++.exe"])
exit()
Problem now is that the terminal window doesn't automatically close. It stays open until I close the notepad window. How can I make the terminal window disappear automatically.
Upvotes: 0
Views: 1315
Reputation: 2884
use Popen
like so
import subprocess
subprocess.Popen(r'C:\Program Files (x86)\Notepad++\notepad++.exe', \
stdout=subprocess.PIPE, shell=False, creationflags = 0x08000000)
Upvotes: 1
Reputation: 1
You could use pythonw.exe: pythonw script.py
Or change its extension to pyw
e.g. script.pyw
and double click on it.
If you do that you should print "Opening Notepad++" to a popup window. See: Python Notification Popup that disappears
Upvotes: 0
Reputation: 993
You need to call the notepad command with start COMMAND
, like in Linux we use COMMAND &
to fork the process into the background. in windows we use the start COMMAND
So you code refactored:
from subprocess import call
print("Opening Notepad++")
call([r"start C:\Program Files (x86)\Notepad++\notepad++.exe"])
exit()
Although note I don't have a windows machine to test on.
Upvotes: 0