Python 执行终端命令

Python执行终端命令有多种方法。

方法一

使用示例:

import os
os.system('ls')

该方法无法输出命令执行结果

方法二

使用示例:

import os
res = os.popen('ls').read()
print(res)

该方法的返回值即命令输出结果

参考

https://www.cnblogs.com/qican/p/11468866.html

posted on 2023-06-25 15:26  Ghlerrix  阅读(48)  评论(0)    收藏  举报  来源