How to close cmd after opening a file using Python in Windows?
Question: 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?


Answer: To execute a child program in a new process use `Popen`

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

