代码之家  ›  专栏  ›  技术社区  ›  tzenes

在Windows上动态重定向子对象的stdout

  •  1
  • tzenes  · 技术社区  · 16 年前

    我注意到了一些关于处理这个问题的其他问题,但似乎都有以下问题:

    • 不在windows上工作
    • 要求子级在检索输出之前完成

    我想做的是调用一个程序。tshark.exe文件)并在运行时处理其输出。

    迄今为止,我已经尝试过:

    • 运行3
    • 过程::可靠

    2 回复  |  直到 16 年前
        1
  •  4
  •   mob    16 年前

    你不需要模块。只需了解管道的形式 open 命令——这些在Windows上很好用。

    my $pid = open (my $cmd_handle, "tshark.exe @options |");
    # on success, $pid holds process identifier of the external command.
    
    while (<$cmd_handle>) {
        # sets $_ to next line of output.
        # Will block until a line of output is ready.
        # Is  undef  when the command is complete.
    
        ... process $_ ...
    }
    close $cmd_handle;   # waits for command to complete if it hasn't completed yet
    
        2
  •  0
  •   jsegal    16 年前

    IPC::Run . IPC::Open2 和 IPC::Open3

    祝你好运!