【发布时间】:2020-05-19 21:46:18
【问题描述】:
我正在将 bash 脚本转换为 python,但是在 python 中执行此操作时:
cmd = r"grep 'name' somefile.log | grep -v 'result=""' | grep -v result='is\ OK'"
results_str = os.system(cmd)
print (results_str,"\n")
我没有得到任何 grep 的输出。如果我从命令行/bash 运行它,我会得到
grep 'name' somefile.log | grep -v 'result=""' | grep -v result='is\ OK'
name="blah", result="the thing I'm trying to grep", action="", info=""
我的 python grep 出了什么问题?
【问题讨论】:
-
os.system不返回您期望的值:stackoverflow.com/a/26005591/11424673 它返回进程退出值,而不是任何标准输出
标签: python