我需要一個函數來暫停腳本的執行,直到按下一個鍵。 我已經試過:按任意鍵繼續在nodejs中
var stdin = process.openStdin();
require('tty').setRawMode(true);
stdin.on('keypress', function (chunk, key) {
process.stdout.write('Get Chunk: ' + chunk + '\n');
if (key && key.ctrl && key.name == 'c') process.exit();
});
但它只是聽了一按鍵並沒有任何反應。該程序不會繼續執行。
我該如何暫停執行?
你有循環中的這個功能嗎?此外,你只是試圖暫停同步功能或異步功能? – EmptyArsenal
您不能暫停在後臺運行的腳本的執行。但我不認爲這是重點,你需要暫停process.stdin/stdout。你可以看看[readline](http://nodejs.org/api/readline.html)包。 – user568109