【问题标题】:Capture tshark stdout output in node.js在 node.js 中捕获 tshark 标准输出输出
【发布时间】:2014-09-13 23:38:16
【问题描述】:

我正在尝试从节点运行 tshark 并使用以下代码检索标准输出输出

var spawn = require('child_process').spawn,
    ts = spawn('tshark',
               ['-i wlan0 -I -R "wlan.fc.type == 0 && wlan.fc.subtype == 4" -e wlan.sa']
              );

ts.stdout.on('data', function (data) {
    console.log('stdout: ' + data);
});

ts.stderr.on('data', function (data) {
    console.log('stderr: ' + data);
});

ts.on('exit', function (code) {
   console.log('child process exited with code ' + code);
});

但我得到一个错误

stderr:在 wlan0 -I -R "wlan.fc.type == 0 && wlan.fc.subtype == 4" -T fields -e wlan.sa 上捕获

stderr:tshark:无法启动捕获会话(不存在此类设备)。 请检查以确保您有足够的权限,并且您指定了正确的接口或管道。

stderr: 0 个数据包被捕获

如果我使用参数直接运行 tshark,它可以正常工作。

有什么可能出错的线索吗?

【问题讨论】:

    标签: javascript linux node.js tshark


    【解决方案1】:

    您现在调用spawn 的方式,tshark 将参数视为一个大引用参数,它无法正确解析它。就好像你这样称呼它:

    tshark "-i wlan0 -I -R ""wlan.fc.type == 0 && wlan.fc.subtype == 4"" -e wlan.sa"
    

    您需要做的是将要传递给spawn 的参数分离到参数数组中的各个项目中:

    ts = spawn('tshark',
               ['-i', 'wlan0', '-I', '-R', 'wlan.fc.type == 0 && wlan.fc.subtype == 4', '-e', 'wlan.sa']
              );
    

    【讨论】:

      猜你喜欢
      • 2014-11-28
      • 1970-01-01
      • 1970-01-01
      • 2021-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-09
      相关资源
      最近更新 更多