使用Python调用外部命令有什么办法?有哪些方式?有实例吗?如何从Python脚本中调用外部命令(就像我在Unix/Linux shell或Windows命令提示符中使用这些命令一样)
查看标准库中的子流程模块
import subprocess
subprocess.run(["ls", "-l"])
子进程相对于系统的优势在于它更加灵活(您可以获得stdout、stderr、“实际”状态代码、更好的错误处理等等)。官方文档建议使用子流程模块替代os.system()
子进程模块为生成新进程和检索结果提供了更强大的工具;使用那个模块比使用这个函数[os.system()]要好。
子流程文档中的“用子流程模块替换旧函数”部分可能有一些有用的方法。Python的旧版本使用call
import subprocess
subprocess.call(["ls", "-l"])
来源:
https://www.srcmini02.com/1025.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_35860.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57