Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

--read Option does not work under Windows #17

Closed
jdl2007 opened this Issue · 2 comments

2 participants

@jdl2007

http://stackoverflow.com/questions/8452957/synchronously-reading-stdin-in-windows

In bin/madge, line 39:

src = JSON.parse(fs.readFileSync('/dev/stdin').toString());

Fails with

fs.js:427
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^
Error: ENOENT, no such file or directory 'C:\dev\stdin'
at Object.fs.openSync (fs.js:427:18)
at Object.fs.readFileSync (fs.js:284:15)
at Object. (C:\Users\jdl\AppData\Roaming\npm\node_modules\madge\bin\madge:39:22)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3

Similar issue for chaplinjs was fixed here:

chaplinjs/chaplin@b0d5b6b

Please assist. Thanks!

@jdl2007

I was able to fix this by doing the following:

Put everything after the 'if (program.read) {...}' block inside a function. If not program.read, call that function. Otherwise, if (program.read), do the following:

if (program.read) {
    var buffer = '';
    process.stdin.resume();
    process.stdin.setEncoding('utf8');
    process.stdin.on('data', function (chunk) {
        buffer += chunk;
    });
    process.stdin.on('end', function () {
        src = JSON.parse(buffer);
        doRest();   // Resume with rest of program
    });
}
else {
    doRest();   // Resume with rest of program
}   

Probably not the most efficient way to do this, but works well enough for my test case (a 3,100 line file).

@pahen
Owner

Thanks! I've added your fix now.

@pahen pahen closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.