为什么 Node.js 脚本控制台在 Windows 8 中会立即关闭?控制台、中会、脚本、Node

2023-09-06 06:36:07 作者:余生一个你

我已经尝试了几乎所有我能找到的脚本示例.每个样本都会在瞬间打开终端.一旦输入输入,即使这也会关闭.这正常吗?

I've tried nearly every example for scripts I can find. Every sample opens the terminal for a split second. Even this closes as soon as input is entered. Is this normal?

    var rl = require('readline');

var prompts = rl.createInterface(process.stdin, process.stdout);

prompts.question("How many servings of fruits and vegetables do you eat each day? ", function  (servings) {
    var message = '';

    if (servings < 5) {
        message = "Since you're only eating " + servings + 
        " right now, you might want to start eating " + (5 - servings) + " more.";
    } else {
        message = "Excellent, your diet is on the right track!";
    }

    console.log(message);

  process.exit();
});

推荐答案

在Tools/Options/Node.js Tools/General中有2个选项可以控制:

There are 2 options that control this in Tools/Options/Node.js Tools/General:

进程存在异常时等待输入进程正常存在时等待输入

Wait for input when process exists abnormally Wait for input when process exists normally

取自 https://nodejstools.codeplex.com/discussions/565665