Does anybody know how to open 2 console/terminal windows to stream logs into them?

28 views
Skip to first unread message

Sergey Lapin

unread,
Oct 15, 2014, 9:51:42 AM10/15/14
to nod...@googlegroups.com
Preferably on windows.

I have several duplex streams which I want log in different places. I would very convinient  to stream them to separate console windows, because I use tdd with live coding. Files are not suitable here.


http://stackoverflow.com/questions/26348823/several-console-instanses-in-node-js

Jimb Esser

unread,
Oct 15, 2014, 2:46:59 PM10/15/14
to nod...@googlegroups.com
You basically only get one console window per console process on Windows.  In theory you could do this with native code, but I doubt anyone has and exposed it in a node module.  So, the simplest solution is to have multiple processes.  The easiest way to do this would be to effectively pipe your logs through a file, assuming you have "tail" installed, or something like it (there's probably one written in node in npm), you can do something like this:

var logger1 = fs.createWriteStream('log1.txt');
var logger2 = fs.createWriteStream('log2.txt');

child_process
.exec('start "Log 1" tail -f log1.txt');
child_process
.exec('start "Log 2" tail -f log2.txt');
logger1
.write('To the first!');
logger2
.write('To the second!');

You can probably do something more complicated with actual pipes instead of files, and have the sub-processes be something like "type" or "cat" which exit automatically upon a broken pipe.
Reply all
Reply to author
Forward
0 new messages