linux - 在C中使用Popen调用tshark没有接收到输出
迷茫
迷茫 2017-04-17 14:36:54
0
1
365

在C中使用popen调用tshark,没有返回输出

例子代码如下:

//开启tshark FILE *fp = popen("tshark -r t_fifo -T pdml", "r"); //读取popen输出 fread(buffer, 1024, 1, fp);

说明:

  1. t_fifo 为创建的FIFO,写入标准PCAP格式报文,用于tshark解析

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all (1)
阿神

1 man popen
You can see
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

such a stream writes to the standard input of the command; the command's standard output is the same as that of the process that called popen(), unless this is altered by the command itself. Conversely, reading from a "popened" stream reads the command's standard output, and the command's standard input is the same as that of the process that called popen().

In other words, the return value is the STDOUT of the new process; if the new process does not print on STDOUT, of course you will not get it;

2 Execute in linutmint17
tshark -r t_fifo -T pdml
echo $?
is 2;
indicates that the command is incorrect and the error message is redirected to STDERR;

If you get error messages in STDOUT, you can use
tshark -r t_fifo -T pdml 2>&1

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!