在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解析
在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解析
7 回答5.4k 阅读
4 回答4.1k 阅读
2 回答5.9k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
1 回答2.4k 阅读✓ 已解决
2 回答837 阅读✓ 已解决
1 回答3.3k 阅读
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