在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
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>