我有一个 c++ 应用程序,我正在其中启动另一个进程(wireshark),如下所示。
if (fp == NULL){
fp = popen(processpath, "r"); //processpath is the process I want to start
if (!fp){
throw std::invalid_argument("Cannot start process");
}
fprintf(fp, d_msg);//d_msg is the input I want to provide to process
} else if(fp != NULL){
fprintf(fp, d_msg);
}
问题是当我执行我的 C++ 应用程序时,它确实启动了 Wireshark 但出现错误End of File on pipe magic during open
我应该怎么做才能避免这种情况?
我还尝试使用 mkfifo 创建一个命名管道并执行它。我用过这样的东西:
if (fp == NULL){
system("mkfifo /tmp/mine.pcap");
fp = popen("wireshark -k -i /tmp/mine.pcap", "r");
if (!fp){
dout << "Cannot start wireshark"<<std::endl;
throw std::invalid_argument("Cannot start wireshark");
}
input = fopen("/tmp/mine.pcap", "wb");
fprintf(input , d_msg);
fclose(input);
} else if(fp != NULL){
input = fopen("/tmp/mine.pcap", "wb");
fprintf(input , d_msg);
fclose(input);
}
但这也没有用。有了这个我得到以下错误:
The file "/tmp/wireshark_mine.pcap_20130730012654_ndbFzk" is a capture for a network type that Wireshark doesn't support
任何帮助,将不胜感激。
非常感谢。