python 执行Linux命令

python execute Linux commands:

1. os.system(command)

eg: 

a = os.system("ls")
print(a)

# a 是命令的返回值,不是命令的输入值。
# a为0说明执行成功,不是0命令执行失败。

  

2. os.popen(command)

eg:

output = os.popen("ls -l")
print(output.read())
output.close()

# output是命令的返回对象,output.read()获取输出内容

 

3. subprocess 

 

posted @ 2021-11-24 15:06  zhuang6  阅读(481)  评论(0编辑  收藏  举报