Post

python读取执行shell后的内容

参考:

读取执行脚本命令的输出

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os

# 读取执行命令后的输出内容
outputFile = os.popen('pwd') # return file
outputStr = outputFile.read()
outputFile.close()
print("outputStr: " + outputStr)



# 读取执行命令的结果
status = os.system("pwd")
// print str\int混排的方式
print("status:", status)
print("status:" + str(status))
print(f"status: {status}")
if status == 256:
    print("errorr")
else:
    print("ok")

This post is licensed under CC BY 4.0 by the author.