Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法从Python正确解析bash的输出_Python_Bash_Parsing_Stdout - Fatal编程技术网

无法从Python正确解析bash的输出

无法从Python正确解析bash的输出,python,bash,parsing,stdout,Python,Bash,Parsing,Stdout,在下面的Python代码中,我通过在Python脚本中嵌入bash命令来调用Makefile。我想检查是否在标准输出上报告了警告。我确实看到了标准输出上的警告,但我的Python代码似乎没有检测到它 Python代码: maker = subprocess.Popen(["bash", "-c", "make"], stdout=subprocess.PIPE) for line in maker.stdout: if "warning:" in line:

在下面的Python代码中,我通过在Python脚本中嵌入bash命令来调用Makefile。我想检查是否在标准输出上报告了警告。我确实看到了标准输出上的警告,但我的Python代码似乎没有检测到它

Python代码:

maker = subprocess.Popen(["bash", "-c", "make"], stdout=subprocess.PIPE)
    for line in maker.stdout:
        if "warning:" in line:
            print "Warning(s) detected in make"                 
stdout上的输出清楚地报告警告:

main.c: In function ‘main’:
main.c:46:14: warning: unused variable ‘options’ [-Wunused-variable]

还可以尝试捕获stderr:

subprocess.Popen(["bash", "-c", "make"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

(正如用户“Barmar”已经指出的,编译器错误消息被发送到stderr。)

也尝试捕获stderr:

subprocess.Popen(["bash", "-c", "make"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

(正如用户“Barmar”已经指出的,编译器错误消息被发送到stderr。)

编译器错误消息被打印到标准错误,而不是标准输出。编译器错误消息被打印到标准错误,而不是标准输出。