在Python中,subprocess模块是一个内置的模块,无需安装。您可以直接使用它来执行外部命令、启动子进程等操作。
以下是一个使用subprocess模块的示例:
import subprocess# 执行外部命令output = subprocess.run(['ls', '-l'], capture_output=True, text=True)print(output.stdout)# 启动子进程subprocess.Popen(['python', 'script.py'])请注意,subprocess模块提供了多种功能和选项,具体使用方法可以参考官方文档:https://docs.python.org/3/library/subprocess.html

