var http = require("http");
var sys = require('util');
var spawn = require('child_process').spawn;
function onRequest(request, response) { //这是createServer的回调函数(事件驱动)
console.log("Request received.");
var mon = spawn("ls", ["-l"]);
var mondata;
mon.stdout.on('data', function (data) {
sys.puts(data);
console.log(data)
mondata = data
})
response.writeHead(200, {
"Content-Type" : "text/plain"
});
response.write('aaa' + mondata);
response.end();
}
http.createServer(onRequest).listen(8888);
console.log("Server has started.");