为了满足我的好奇心基因,我想玩 bash/node 组合。我不知道如何让这两个一起说话。发现TTY.JS时,我脸上露出灿烂的笑容;-)
如何将终端的输出(sdtout?)提供给节点?我考虑将流重定向到文件并通过'fs'模块使用节点读取它。但我打赌一定有更漂亮的方式
提前致谢。
像这样的东西应该将终端输出发送到节点
var app = require('express').createServer(),
io = require('socket.io').listen(app),
sys = require('util'),
exec = require('child_process').exec;
app.listen(4990);
io.sockets.on('connection', function(socket) {
socket.on('console', function(command, callBack) {
// client sends {command: 'ls -al'}
function puts(error, stdout, stderr) {
socket.emit('commandresult', stdout);
}
exec(command.command, puts);
});
});
希望这可以帮助