Skip to content

Instantly share code, notes, and snippets.

@steveandroulakis
Last active December 23, 2015 23:29
Show Gist options
  • Save steveandroulakis/6710022 to your computer and use it in GitHub Desktop.
Save steveandroulakis/6710022 to your computer and use it in GitHub Desktop.
run windows process in node.js
// pre-req, msconvert.exe in PATH smsdm.cpl
// terminal
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
var terminal = require('child_process').spawn('cmd');
// Load the http module to create an http server.
terminal.stdin.write('msconvert.exe\n');
terminal.stderr.on('data', function (data) {
response.write('stderr: ' + data);
terminal.stdin.write('quit\n');
response.end();
});
terminal.stdout.on('data', function (data) {
response.write('stdout: ' + data);
});
terminal.on('exit', function (code) {
console.log('child process exited with code ' + code);
});
});
// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(80);
// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:80/");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment