Gntem
Gntem

Reputation: 7165

How to interact with multiple console windows?

how can interact with multiple console windows, from one node.js script?

so far i have researched a bit, and not have found anything that covers my case.

What i want to accomplish is to have one main console window, which it reads my input,

1. action#1
2. action#2

> do 1 // select action

and it would redirect its output to another console window named as Logger which shows the stdout of the action that the user selected, but keeps the main "select action" console window clean.

Upvotes: 0

Views: 425

Answers (1)

Gntem
Gntem

Reputation: 7165

well i manage to find a way around it, since i wanted to stay with node.js all the way.

start.js

var cp = require("child_process");
cp.exec('start "Logger" cmd /K node logger.js',[],{});
cp.exec("start cmd /K node startAdminInterface.js",[],{});
setTimeout(function(){process.exit(0);},2000);

logger.js

var net = require('net');
net.createServer(function (socket) {
  socket.on('data',function(d){
    console.log(": "+d.toString("utf8"));
  });
  socket.on('error',function(err){
    console.log("- An error occured : "+err.message);
  });
}).listen(9999);

startAdminInterface.js

var net = require("net");
var logger = net.connect(9999);
var readline = require('readline'),
    rl = readline.createInterface(process.stdin,process.stdout);
rl.setPrompt('> ');
rl.prompt();
rl.on('line', function(line) {
  logger.write(line);
  rl.prompt();
}).on('close', function() {
  process.exit(0);
});

bottom, line its a workaround not exactly what i was after, put i saw potential, on logger.js it could listen from multiple sources, which is an enormous plus in the application that i'm building.

Upvotes: 1

Related Questions