strings <FILE NAME> | grep "Version = <VERSION STRING>" > /dev/null
我需要保存以下脚本逻辑的命令返回码和命令输出。
目前,我使用了以下代码:
strings_out = subprocess.Popen(('strings', file), stdout=subprocess.PIPE)
grep_output = subprocess.check_output(('grep', "Version = " + version_string), stdin=strings_out.stdout)
strings_out.wait()
我遇到错误了
subprocess.CalledProcessError: Command '('grep', 'Version = <VERSION STRING>')' returned non-zero exit status 1
我猜测 check_output 内存用尽了。
我的 subprocess 使用有什么问题吗?
strings_out.wait()
。有可能grep
命令在第一个命令完成之前就已经运行,例如如果strings
命令的输出很大。 - Swadhikarstrings
命令的输出读入到 Python 中,并使用 Python 正则表达式(或者对于简单的子字符串搜索,甚至只需使用in
)来测试您要查找的版本字符串是否存在。 - alani