Last active
December 24, 2015 23:39
-
-
Save radiodario/6881415 to your computer and use it in GitHub Desktop.
Compiling on the fly for rich_
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
var fs = require('fs'); | |
var code = '#include <stdio.h>\n int main (void){printf("testing");char x; x = getchar();printf("READ: %c",x);return 0;}'; | |
var child = require('child_process'); | |
fs.writeFile('tmp.c',code,function(){ | |
console.log('Code written to disk'); | |
var args = ['-o', process.cwd() + '/run', process.cwd() + '/tmp.c']; | |
console.log(args.join(' ')); | |
var compiler = child.exec('gcc', args); | |
compiler.stdout.on('data',function(data){ | |
console.log('stdout: '+data); | |
}); | |
compiler.stderr.on('data',function(data){ | |
console.log('ERROR: '+data); | |
}); | |
compiler.on('close',function(code,signal){ | |
console.log("Program compiled : )"); | |
var TEST_EXEC = process.cwd() + '/run'; | |
console.log(TEST_EXEC); | |
var spawn = child.spawn; | |
var test = spawn(TEST_EXEC); | |
test.stdout.on('data', function (data) { | |
console.log('stdout: ' + data); | |
}); | |
test.stderr.on('data', function (data) { | |
console.log('stderr: ' + data); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment