当我在脚本中使用os和子进程运行命令,然后使用ntest测试脚本时,即使grep命令假定是名称,我也会得到数字作为grep命令的结果。
例如:
command=grep -o 'import.*' filename
out = subprocess.check_output(command,stderr=subprocess.STDOUT,shell=True)
print(out)
for i in out:
print(i)
输出:
b'import random\nimport time\nimport re\nimport pytest\nimport Pass\nimport Node\nimport StorageAggregate\nimport Volume, VolumeClone\nimport Application, ApplicationVolume\nimport VolumeQtree\nimport Lun\nimport VolumeDoesNotExist, ApplicationAlreadyExists, \\\n'
105
109
112
111
114
116
32
114
97
110
100
111
109
10
105
109
112
111
114
116
32
116
105
109
101
10
105
109
112
111