因此,我假设PyCharm在自己的终端上运行脚本,而不是依赖cmd或PowerShell。
不一定。PyCharm显示自定义错误消息并不意味着它不依赖cmd。下面是一个Python脚本,它使用cmd模拟PyCharm的功能:
# So we can launch a process from Python
import subprocess as sp
# Launches a Python process for a specific file
# `stdout=sp.DEVNULL` suppresses the process output
# so that's why there is no detailed error message
child = sp.Popen(["python", "file.py"], stdout=sp.DEVNULL)
# Start the Python process
process = child.communicate()[0]
# Returns the process exit code
# If the process finishes without errors, it'll return 0
# otherwise, it'll return a "random" value
exit_code = process.returncode
# Displays to stdout the completely unhelpful message
print(f"Process finished with exit code {exit_code} ({hex(exit_code)})")
不管怎样,
here's what PyCharm says
最初,终端仿真器使用默认的系统shell运行,但它支持许多其他shell,如Windows PowerShell、命令提示符cmd.exe、sh、bash、zsh、csh等。