Created
February 23, 2017 16:30
-
-
Save jmerle/fe821084d29478dd260e1b774f5a4666 to your computer and use it in GitHub Desktop.
A little Hack Man run script for Windows
This file contains hidden or 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
const fs = require('fs'); | |
const spawn = require('child_process').spawn; | |
if (process.argv.length !== 3) throw new Error('Usage: node app.js <wrapper-commands file>'); | |
var runMatch = function(wrapperCommandsFile) { | |
return new Promise(function(resolve, reject) { | |
fs.readFile(wrapperCommandsFile, 'utf8', function(error, data) { | |
if (error) reject(error); | |
var config = JSON.parse(data); | |
var cmd = spawn('java', ['-jar', 'engine/game-wrapper.jar', data]); | |
var stdout = []; | |
cmd.stdout.on('data', function(data) { | |
data = data.toString(); | |
if (data.trim() !== '') stdout.push(data.trim()); | |
}); | |
cmd.on('error', function(error) { | |
reject(error); | |
}); | |
cmd.on('close', function(code) { | |
if (code !== 0) reject(new Error('The engine process exited with code ' + code)); | |
resolve(stdout.join('\n')); | |
}); | |
}); | |
}); | |
}; | |
// Basic usage | |
runMatch(process.argv[2]).then(function(stdout) { | |
console.log(stdout); | |
}).catch(function(error) { | |
console.error('Something went wrong: ' + error.message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment