-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproc.js
More file actions
41 lines (37 loc) · 1.08 KB
/
proc.js
File metadata and controls
41 lines (37 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var os = require('os'),
fs = require('fs'),
childProcess = require('child_process'),
javac = function(){
childProcess.exec('javac ./Proc.java',function(err,stdout,stderr){
console.info('out:' + stdout);
if (!err) {
childProcess.exec('java ./Proc');
}
});
};
process.stdin.setEncoding('utf8');
var stdinBuffer = [];
var importDummy = '/*IMPORT DUMMY*/'
codeDummy = '/*DUMMY*/',
javatemplate = importDummy + 'public class Proc {public static void main(String[] args) {'+codeDummy+'}}',
finalJava = '';
process.stdin.on('readable', function() {
var chunk = process.stdin.read();
if (chunk !== null) {
chunk = chunk.replace(os.EOL,'')
if (chunk == ':show') {
stdinBuffer.forEach(function(d){
process.stdout.write(finalJava);
});
} else {
stdinBuffer.push(chunk);
finalJava = javatemplate.replace(codeDummy,stdinBuffer.join(';') + ';');
process.stdout.write(finalJava+os.EOL);
fs.writeFileSync('./Proc.java',finalJava,'utf8');
javac();
}
}
});
process.stdin.on('end', function() {
process.stdout.write('end');
});