【问题标题】:pushing tty output to node将 tty 输出推送到节点
【发布时间】:2012-06-25 16:52:54
【问题描述】:

为了满足我的好奇心基因,我想玩 bash/node 组合。 我不知道如何让这两个一起说话。发现TTY.JS 时,我脸上露出灿烂的笑容;-)

如何将终端的输出(sdtout?)提供给节点?我考虑将流重定向到文件并通过'fs'模块使用节点读取它。但我打赌一定有更漂亮的方式

提前致谢。

【问题讨论】:

    标签: bash node.js tty


    【解决方案1】:

    这样的东西应该将终端输出发送到节点

    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);
        });
    });​
    

    希望对你有帮助

    【讨论】:

    • 确实如此,确实如此 ;-) 谢谢!
    猜你喜欢
    • 1970-01-01
    • 2018-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-25
    • 1970-01-01
    • 2021-03-18
    相关资源
    最近更新 更多