zhangcnblogs

如果要python实现系统命令或者调用脚本,python中可以利用os或者subprocess模块实现:

一、os模块:

1 # coding:utf-8
2 import os #导入os模块

3 command = os.system(\'netstat\') # os.system获取不到返回值

1 # coding:utf-8
2 import os #导入os模块
3 
4 command = os.popen(\'ping www.baidu.com\') # os.popen可以获取到返回值
5 print command.read()

二、subprocess模块:

subprocess.run(*popenargs, input=None, timeout=None, check=False, **kwargs) #官方推荐的使用参数

subprocess.call(*popenargs, timeout=None, **kwargs) #

subprocess.Popen() #上面各种方法的底层封装
1 import subprocess
2 
3 c = subprocess.Popen(\'ping www.baidu.com\')
4 c.wait()
5 print c

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-08-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-06
  • 2021-08-28
  • 2022-12-23
猜你喜欢
  • 2021-12-06
  • 2022-12-23
  • 2021-05-21
  • 2021-07-07
  • 2021-11-10
  • 2021-12-16
  • 2022-12-23
相关资源
相似解决方案