[英]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. 我编写了一个使用Python打开在执行过程中创建的特定文件(txt)的程序。 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. 我已经尝试了以下两个选项来在script.py中使用Python打开文件。
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.
问题是我想在记事本中打开文本文件后关闭cmd提示。 But I have to either manually close the cmd prompt or close the notepad file which automatically closes the cmd prompt.
但是我必须手动关闭cmd提示符或关闭记事本文件,该文件会自动关闭cmd提示符。
So my question is how can I close the cmd prompt and keep the notepad file open? 所以我的问题是如何关闭cmd提示并保持记事本文件打开?
To execute a child program in a new process use Popen
要在新进程中执行子程序,请使用
Popen
from subprocess import Popen
Popen( [ "notepad.exe", "arg1", "arg2", "arg3" ] )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.