我想运行一些预定义的 shell 命令并将它们作为纯文本返回到 http 服务器中。(1) 处写入的内容正在提供给我的浏览器,但 (2) 处最终必须是标准输出的内容没有提供。任何人都可以帮助我如何实现这一目标吗?
var http = require('http'),
url = require('url'),
exec = require('child_process').exec,
child,
poort = 8088;
http.createServer(function(req, res) {
 res.writeHead(200, {'Content-Type': 'text/plain'});
    var pathname = url.parse(req.url).pathname;
    if (pathname == '/who'){
        res.write('Who:'); // 1
        child = exec('who',
                     function(error, stdout, stderr){
                        res.write('sdfsdfs');   //2
                     })
    } else {
        res.write('operation not allowed');
    }
 res.end();
}).listen(poort);