子流程调用&;检查输出Python2.7

子流程调用&;检查输出Python2.7,python,subprocess,Python,Subprocess,我正在阅读有关子流程模块的内容,对此感到非常困惑。在我的搜索功能下,当grep在文本文件中找不到用户输入时,我想使用subprocess.check_output返回我选择的打印错误消息。我该怎么做呢?使用Python2.7 import subprocess def menu(): usr = raw_input("Press 1 if you are creating a new entry, press 2 for search or 3 to exit") if usr

我正在阅读有关子流程模块的内容,对此感到非常困惑。在我的搜索功能下,当grep在文本文件中找不到用户输入时,我想使用subprocess.check_output返回我选择的打印错误消息。我该怎么做呢?使用Python2.7

import subprocess

def menu():
    usr = raw_input("Press 1 if you are creating a new entry, press 2 for search or 3 to exit")
    if usr == '1':
        collect()
    if usr == '2':
        search()
    if usr == '3':
        sys.exit()
    if usr == '4':
        subprocess.call(['vim', '-c', '10', 'book.txt'])
def search():
    inp = raw_input("Please enter a name:")
    subprocess.call(['rgrep', '-e', inp])
    search()
def collect():
    def do_global():
        global name, ac, number
        name = raw_input("Name")
        ac = raw_input("Area Code")

要了解退出状态
grep
可能产生的结果,请参阅

您可能会对子流程(如模块)的更高级别包装感兴趣。Sebastian,我在哪里可以找到有关模块的文档=您在回答中提供的0。我想自己读更多这方面的内容。感谢you@toykloner例如你可以从六点开始。
if subprocess.call(['rgrep', '-e', inp]) != 0: # rgrep failed
   print("error message of your choosing")