[英]How to get only one specific line from subprocess output
I know how to search if specific word exists in subprocess output. 我知道如何搜索子过程输出中是否存在特定单词。 But how can I print out only one specific line, if I know this line always looks like: 但是,如果我知道这一行总是看起来像这样,我该如何只打印出一行:
This is the line: some text
"Some text" can have different values. “某些文本”可以具有不同的值。
What I have: 我有的:
variable = subprocess.call(["some", "command"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = output.communicate()
What I want to get after executing the script: 执行脚本后我想要得到什么:
This is the line: some text
import subprocess
p = subprocess.Popen(["some", "command"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
stdout=stdout.split("\n")
for line in stdout:
if line.startswith("This is the line:"):
print line
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.