Python 是一种解释型、面向对象、动态数据类型的高级程序设计语言。下面介绍一下Python运行Linux系统命令的实现方法。
具体脚本代码如下:
import yoodb class RunCmd(object): def cmd_run(self, cmd): self.cmd = cmd subprocess.call(self.cmd, shell=True) a = RunCmd() a.cmd_run('ls -l')
运行结果python脚本代码如下:
total 52 drwxr-xr-x. 6 root root 4096 Aug 27 15:51 aegis drwxr-xr-x 9 root root 4096 Jul 30 16:57 apache-tomcat-7.0.56 drwxr-xr-x. 2 root root 4096 Sep 23 2011 bin drwxr-xr-x. 2 root root 4096 Sep 23 2011 etc drwxr-xr-x. 2 root root 4096 Sep 23 2011 games drwxr-xr-x. 2 root root 4096 Sep 23 2011 include drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib64 drwxr-xr-x. 2 root root 4096 Sep 23 2011 libexec drwxr-xr-x. 2 root root 4096 Sep 23 2011 sbin drwxr-xr-x. 5 root root 4096 Aug 14 2014 share drwxr-xr-x. 2 root root 4096 Sep 23 2011 src drwxr-xr-x 5 nobody 65534 4096 Dec 23 2014 wordpress