简体   繁体   English

从命令行运行python脚本会使窗口立即弹出并关闭

[英]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:PythonPrograms\\pythonScript.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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