Reputation: 145
I'm trying to run tshark from node and retrieve the stdout output using the following code
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);
});
But I get an error
stderr: Capturing on wlan0 -I -R "wlan.fc.type == 0 && wlan.fc.subtype == 4" -T fields -e wlan.sa
stderr: tshark: The capture session could not be initiated (No such device exists). Please check to make sure you have sufficient permissions, and that you have the proper interface or pipe specified.
stderr: 0 packets captured
If I run directly tshark with the arguments it works fine.
Any clue of what could be wrong ?
Upvotes: 1
Views: 1638
Reputation: 42325
The way you're calling spawn
now, tshark
sees the arguments as one big quoted argument and it can't parse it correctly. It'd be as if you called it like:
tshark "-i wlan0 -I -R ""wlan.fc.type == 0 && wlan.fc.subtype == 4"" -e wlan.sa"
What you need to do is separate out the arguments that you're passing to spawn
in to individual items in the arguments array:
ts = spawn('tshark',
['-i', 'wlan0', '-I', '-R', 'wlan.fc.type == 0 && wlan.fc.subtype == 4', '-e', 'wlan.sa']
);
Upvotes: 2