 
                        在C中使用popen调用tshark,没有返回输出
例子代码如下:
//开启tshark
FILE *fp = popen("tshark -r t_fifo -T pdml", "r");
//读取popen输出
fread(buffer, 1024, 1, fp);说明:
t_fifo 为创建的FIFO,写入标准PCAP格式报文,用于tshark解析
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
1 man popen
可以看到
The return value from popen() is a normal standard I/O stream in all respects save that it must be closed with pclose() rather than fclose(3). Writing to
也就是说,其返回值是新进程的STDOUT ; 如果新的进程没有在STDOUT 给出打印,你当然都不到;
2 在linutmint17 中执行
tshark -r t_fifo -T pdml
echo $?
为2;
说明命令不对,并且错误信息被重定向到STDERR了;
如果你向在STDOUT 中获得错误信息,可以使用
tshark -r t_fifo -T pdml 2>&1