zud
zud

Reputation: 105

Close the terminal window after doing something

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

Answers (3)

vencaslac
vencaslac

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

repassyl
repassyl

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

Jamie Lindsey
Jamie Lindsey

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

Related Questions