0

Iam trying to execute a terminal command using node.js spawn

tshark -i 3 -Y "ipp contains 02:00:00:00" -T pdml > ggggg.xml

for that am using the code

var args = ['-i', '3',
              '-Y',         
             "ipp contains 02:00:00:00" ,'-T','pdml','>','ggggg.xml'];
 

console.log(args)

var child = spawn("tshark", args, {cwd: workDir});
        child.stdout.on('data', function(data) {
          
          console.log(data.toString())        
        });
      
        child.stderr.on('data', function(data) {
          console.log('stdout: ' + data);
           
        });

        child.on('close', function(code) {
          console.log('closing code: ' + code);
              
        });
        
    

But it treated greater than >as string">" and getting output as

tshark: Invalid capture filter "> gggggg.xml" 
    
    That string isn't a valid capture filter (syntax error).
    See the User's Guide for a description of the capture filter syntax.

How can i use > without string

2

1 Answer 1

2

You can use file streams to put all output from spawned hark to g.xml.
Example:

// don't need ">" in args
var args = [' 02:00:00:00' ,'-s','pdml'],
    logStream = fs.createWriteStream('./xml');

var spawn = require('child_process').spawn,
    child = spawn('tshark', args);

child.stdout.pipe(logStream);
child.stderr.pipe(logStream);

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

Because of child here is a stream, you can just pipe it into your logged file stream.

Sign up to request clarification or add additional context in comments.

6 Comments

yes one more thing..ur coding is working..but it did not output the valid xml file....some attributes are missing
I will get the full xml file when i manully exit the running terminal using ctrl+C ..but in code i tried to exit the process and killed the child process but not getting the full output in that case also
Tried using 'exit' event instead of 'close' for child?
But it does not goes inside 'exit' event or 'close' event..that is the main problem..also i cannot identify the process is completed or not and i quil the terminal by ctrl+c command
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.