python调用linux shell命令

使用os 模块及command模块的相关方法可以在python中调用linux shell命令。

1.os模块的system方法

os.system(cmd):此方法会创建子进程运行外部程序,方法只返回外部程序的运行结果;比较适用于外部程序没有输出结果的情况。

2.os模块的popen方法

os.popen(cmd):使用popen方法可以得到外部程序的输出结果,需要使用read( )得到命令输出内容。

3.commands模块的 getoutput方法

commands.getoutput( ):把输出结果当作字符串返回。

posted @ 2013-05-18 14:08  smstars_test  阅读(2718)  评论(0编辑  收藏  举报