linux:

python执行shell脚本常用的方法

import os

val=os.system("shell语句") 

>>> val=os.system("more /tmp/web.access.log |grep 222.132.79.77 -wc")
826
>>> print val
0

val=os.popen("shell语句").read()  val=可以获取返回值

>>> val=os.popen("more /tmp/web.access.log |grep 222.132.79.77 -wc").read()
>>> print val
826

windows:

在windows执行的时候,有时候路径是带有空格的,处理方法有两种

第一种," "括起来空格路径字符串

os.system(r'D:\"Program Files"\firefox.exe')

第二种:使用win特有的命令

os.startfile(r'D:\Program Files\firefox.exe')

 

 

相关文章:

  • 2022-12-23
  • 2022-01-20
  • 2021-11-19
  • 2021-11-19
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
  • 2022-02-11
猜你喜欢
  • 2021-12-24
  • 2022-01-17
  • 2022-01-03
  • 2022-01-02
  • 2021-12-23
  • 2021-10-10
  • 2023-03-04
相关资源
相似解决方案