我正在尝试制作和c REPL,所以我需要与stdin交互多少次c代码需要。目前有一个这个代码(只有一次)
const spawn = require('child_process').spawn;
const gcc = spawn('gcc', ['-Wall', 'main.c', '-o', 'main', '-lm']);
gcc.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
gcc.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
gcc.on('close', (code) => {
console.log(`child process exited with code ${code}`);
const child = spawn('./main')
child.stdin.setEncoding('utf-8');
child.stdout.pipe(process.stdout)
child.stdin.write("5\n");
child.stdin.end();
});
任何线索?