c++ - 如何使用 CreateProcess 调用 tshark 将捕获文件转换为 txt

标签 c++ windows visual-studio wireshark tshark

我正在尝试从使用 Visual Studio 编译的 C++ 程序调用 tshark。有些通话有效,但其他通话则无效。我能够启动捕获到文件:

STARTUPINFO startupInfo={sizeof(startupInfo)};
PROCESS_INFORMATION processInfo;
const char * args = " -i \"Ethernet 9\" -w C:\\Users\\raymond\\Documents\\Debug\\Ethernet_9.cap -b duration:90 -b files:2\"";

CreateProcess("C:\\Program Files\\Wireshark\\tshark.exe", const_cast<char *>(ss.str().c_str()), NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &startupInfo, &processInfo);

但我无法将捕获文件转换为文本:

STARTUPINFO startupInfo={sizeof(startupInfo)};
PROCESS_INFORMATION processInfo;
const char * args = " -i - < \"C:\\Users\\raymond\\Documents\\Ethernet_9.cap\" > \"C:\\Users\\raymond\\Documents\\Ethernet_9.txt";

CreateProcess("C:\\Program Files\\Wireshark\\tshark.exe", const_cast<char *>(ss.str().c_str()), NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &startupInfo, &processInfo);

打印的只是“Capturing on 'Standard input'”,但与在命令行上运行该命令相反,没有任何输出,并且从不打印已处理数据包的数量。

尝试与 system() 类似的操作在同一个 tshark 调用上也会出现奇怪的行为。

如果我尝试在程序仍在运行时关闭新窗口,则会打印以下内容: (tshark.exe:8628):CaptureChild-警告**:sync_pipe_stop:强制子进程退出

最佳答案

您不能将重定向操作与 CreateProcess 一起使用 - 重定向由命令处理器 cmd.exe 处理,当您使用 CreateProcess< 时,该命令处理器会被绕过。/.

您可能只想使用 C 中的 system 命令,该命令使用系统 shell(Windows 上的 cmd.exe):

system("C:\\Program Files\\Wireshark\\tshark.exe -r \"C:\\Users\\raymond\\Documents\\Ethernet_9.cap\" > \"C:\\Users\\raymond\\Documents\\Ethernet_9.txt\"");

正如 @RossJacobs 还提到的,您需要使用 -r 而不是 -i 来读取文件。

关于c++ - 如何使用 CreateProcess 调用 tshark 将捕获文件转换为 txt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59032929/

相关文章:

c# - 数据模板 x :Bind namespace error

sql-server - 在 Visual Studio 2015 中添加 SSDT BI 模板

javascript - 仅显示 javascript 对象的对象属性

c++ - 可以在数据报套接字中用于发送和接收吗?

c++ winsock 代码在 visual studio 2010 中的原始解决方案/项目中不起作用

c++ - 检测文件是否已更改的可靠方法

c# - Message.show() 在另一台计算机桌面上?

C++ MuParser 解析不符合预期

c++ - boost ,shared_ptr 与 weak_ptr?什么时候用?

python 2.7 : output utf-8 in Windows console