There is a local server. If you write 127.0.0.1/?com=ls in the request, then the ls should be executed in the terminal. I managed to transfer info from ls to the server, but it is displayed only to the console. Why console.log(ls) work, and response.write(ls) doesn't?
var url = require("url"), http = require('http'), process = require('child_process'), qs = require("querystring"), fs = require('fs'), port = 8080; var server = http.createServer(function(request, response) { response.writeHead(200, {"Content-Type": "text/html"}); var query = url.parse(request.url).query; params = qs.parse(query); if(params.com=='ls'){ process.exec('ls', function(err, ls){ console.log(ls); response.write(ls); }); } response.end(); }); server.listen(port); console.log('Browse to http://127.0.0.1:' + port);
responce.end();and only after that the callback is called. But at this moment an attempt to callresponce.write()will not lead to anything good. - Yaantresponce.end()inside the callback. - Yaant