Created
July 13, 2010 04:47
-
-
Save adamwiggins/473464 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var sys = require('sys') | |
var net = require('net') | |
var child_process = require('child_process') | |
if (!process.env.PORT) { | |
sys.puts('Must specify PORT') | |
process.exit() | |
} | |
var port = parseInt(process.env.PORT) | |
sys.puts('Listening on port ' + port) | |
cmd = process.argv.slice(2, 99) | |
var server = net.createServer(function (socket) { | |
socket.setEncoding('utf8') | |
socket.addListener('connect', function () { | |
sys.puts('Got connection, spawning process: ' + cmd.join(' ') + '\n------------------') | |
ps = child_process.spawn(cmd[0], cmd.slice(1, 99)) | |
// Input | |
socket.addListener('data', function (data) { | |
sys.puts('input: ' + data) | |
ps.stdin.write(data) | |
}) | |
// Output | |
ps.stdout.addListener('data', function (data) { | |
socket.write(data) | |
sys.print(data) | |
}) | |
ps.stderr.addListener('data', function (data) { | |
socket.write(data) | |
sys.print(data) | |
}) | |
ps.addListener('exit', function () { | |
socket.end() | |
}) | |
}) | |
socket.addListener('end', function () { | |
sys.puts('-----------------\nDone') | |
process.exit() | |
}) | |
}) | |
server.listen(port) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ PORT=9000 node facehugger.js -- /your/program arg1 arg2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment