简体   繁体   中英

Writing multiple times to process stdin in node.js

I'm a beginner in Node.js and also in programming. Perhaps I miss something very basic. I have two scripts which have to talk with each other in the command line. The first script gives numbers and the other makes some math and returns the answer. The first script was written by someone else and I don't know what is there. Te second script is mine. It reads the numbers in stdout and writes the answer in stdin. The first script "sees" the answer only after process.stdin.end(). But I have to read and write multiple times. What should I do? My code looks like this:

var process = shell.exec('node first.js', {async:true});
process.stdout.on('data', function(data) {
   process.stdin.write("" + evalStr(data) + "\n");
   process.stdin.end();
});

使用process.stdin.write(data + "\\n")而不是使用evalStr()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM