[英]Running python scripts from a command line makes window pop and close immediately
I created a test file called pythonScript.py
and I also created a batch file called pythonScript.bat
. 我创建了一个名为
pythonScript.py
的测试文件,还创建了一个名为pythonScript.bat
的批处理文件。 Both of these files are in my C:\\Python Programs
file that a created to store my scripts. 这两个文件都在我的
C:\\Python Programs
文件中,该文件是为了存储我的脚本而创建的。 The contents of pythonScript.bat
is: @py.exe C:\\Python Programs\\pythonScript.py %*
. pythonScript.bat
的内容是: @py.exe C:\\Python Programs\\pythonScript.py %*
。 When I press Ctrl+R
and type pythonScript
a command box pops up and then closes just as quick as it opened. 当我按
Ctrl+R
并键入pythonScript
将弹出一个命令框,然后以与打开时一样快的速度关闭它。 I'm running Windows 10. Any advice? 我正在运行Windows10。有什么建议吗?
You need to enclose the path to the Python script in pythonScript.bat
within double-quotes: 您需要将
pythonScript.bat
Python脚本的路径括在双引号中:
@py.exe "C:\Python Programs\pythonScript.py" %*
This is because it contains a space. 这是因为它包含一个空格。 Without the
""
, py.exe
receives two command line arguments C:Python
and Programs\\pythonScript.py
. 如果没有
""
, py.exe
接收两个命令行参数C:Python
和Programs\\pythonScript.py
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.