我正在用nodejs编写解析器。该解析器应逐行读取文件,进行一些行解析,并在读取下一行之前要求用户输入。我可以逐行正确读取文件,但是使用readline询问用户数据无效。有人从未尝试过这样的事情吗?
async function processLineByLine() {
const fileStream = fs.createReadStream('data.txt');
const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity
});
const il = readline.createInterface({
input: process.stdin,
output: process.stdout
});
for await (const line of rl) {
var matches = /id\=\"(\w+)\".+(NT\d{1,2})/.exec(line);
var matID = matches[1].match(/\d+/g)[0];
il.question("Insert color data",(reply) => {
console.log(reply);
});
}
rl.close();
}
processLineByLine();
我也使用了此版本
async function processLineByLine() {
const fileStream = fs.createReadStream('data.txt');
const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity
});
for await (const line of rl) {
var matches = /id\=\"(\w+)\".+(NT\d{1,2})/.exec(line);
var matID = matches[1].match(/\d+/g)[0];
const il = readline.createInterface({
input: process.stdin,
output: process.stdout
});
il.question("Insert color data",(reply) => {
console.log(reply);
il.close();
});
}
rl.close();
}
processLineByLine();