简体   繁体   中英

How to close cmd after opening a file using Python in Windows?

I have a written a program using Python to open a particular file (txt) which it creates during execution. I have made a batch file to access the script using command line. The batch script is as follows:

@echo off
python F:\program\script.py %*

I have tried these two options for opening the file with Python in script.py.

subprocess.Popen(name, shell=True)

and

os.system('"'+name+'"') 

I have further made a keyboard shortcut for the batch script. The problem is I want the cmd prompt to close after the text file opens in notepad. But I have to either manually close the cmd prompt or close the notepad file which automatically closes the cmd prompt.

So my question is how can I close the cmd prompt and keep the notepad file open?

To execute a child program in a new process use Popen

from subprocess import Popen
Popen( [ "notepad.exe", "arg1", "arg2", "arg3" ] )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM