龙空技术网

python运行shell命令

最后一个NPE 734

前言:

如今大家对“shell执行python命令”大约比较关心,兄弟们都需要了解一些“shell执行python命令”的相关内容。那么小编同时在网摘上收集了一些有关“shell执行python命令””的相关文章,希望同学们能喜欢,各位老铁们快快来学习一下吧!

import osret = os.popen("date").read()print(ret)

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

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

标签: #shell执行python命令