Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use spawn instead of exec to allow "real-time" feedback #1

Open
abh opened this issue Mar 15, 2012 · 3 comments
Open

use spawn instead of exec to allow "real-time" feedback #1

abh opened this issue Mar 15, 2012 · 3 comments
Assignees
Milestone

Comments

@abh
Copy link

abh commented Mar 15, 2012

It'd be nice if there was an option to get each hop as traceroute finds them, rather than just a result when it's all done.

@jaw187
Copy link
Owner

jaw187 commented May 31, 2012

abh, haven't been on GitHub in a while and never realized that there was a comment. Thanks for the suggestion! I'll look to rewrite it ASAP.

@ghost ghost assigned jaw187 May 31, 2012
@abh
Copy link
Author

abh commented May 31, 2012

for my application I wanted to use mtr instead of regular traceroute, I'm including the code I used below in case it's useful to you:

"use strict";

var spawn = require('child_process').spawn;

function trace(host, opts, cb) {
    if (!opts.cycles) { opts.cycles = 3; }
   var mtr = spawn('mtr', [ '--raw', '--report-cycles', opts.cycles, host ]);
   mtr.stderr.on('data', function (data) {
       console.error("ERROR: " + data);
   });
   mtr.stdout.on('data', function (data) {
       var lines = data.toString().split('\n');
       console.log("lines", lines);
       for (var i=0; i < lines.length; i++) {
           if (lines[i] === '') { break; }
           var r = lines[i].split(' ');
           r[1] = parseInt(r[1], 10);
           if (r[0] === 'p') {
               r[2] = parseInt(r[2], 10);
           }
           cb(null, r);
       }
   });
   mtr.on('exit', function(code) {
       console.log("mtr done!");
       cb(null, ["x", code]);
       if (code !== 0) {
           console.error('mtr process exited with code ' + code);
       }
   });
}

exports.trace_raw = function (host, opts, cb) {
    if (typeof opts === 'function') {
        cb = opts;
        opts = {};
    }
    trace(host, opts, cb);
};

@jaw187 jaw187 added this to the 1.0.0 milestone Feb 8, 2016
@jaw187
Copy link
Owner

jaw187 commented Mar 13, 2016

@abh Not sure if you're still interested or not, but I finally did as you suggested :) Latest code in master has it, but I've yet to publish version 2.0.0 to NPM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants