python运行shell命令

2018/04/08

python运行shell命令

import os

ret = os.popen("date").read()

print(ret)

先导入os模块,然后通过popen方法执行shell命令,并通过read方法读取执行结果,最后打印输出。

[root@iZputslk1bvy2iZ ~]# python test.py 
Sat Apr  7 13:00:33 CST 2018


Post Directory