python调用命令行的方法是什么
在Python中,可以使用subprocess
模块来调用命令行。具体来说,可以使用subprocess.run()
函数来执行系统命令。例如:
import subprocess
result = subprocess.run(["ls", "-l"], capture_output=True, text=True)
print(result.stdout)
上面的代码会在Python中调用ls -l
命令,并将输出结果打印出来。可以根据实际情况修改命令和参数。