Node.js 从当前进程和子进程读取控制台输入
要读取当前进程的控制台输入,请使用以下推荐模式:Node.js 从当前进程和子进程读取控制台输入,node.js,Node.js,要读取当前进程的控制台输入,请使用以下推荐模式: const readline=require('readline')。createInterface({ 输入:process.stdin, 输出:process.stdout }); readline.question('messageforuser',input=>{ //... }); 它很好用。我还需要运行一些命令,如: const { execSync } = require('child_process'); execSync(cm
const readline=require('readline')。createInterface({
输入:process.stdin,
输出:process.stdout
});
readline.question('messageforuser',input=>{
//...
});
它很好用。我还需要运行一些命令,如:
const { execSync } = require('child_process');
execSync(cmd, { stdio: 'inherit' }); // now input for and output from child process is handeled transparently
它也很好用
当我尝试将两者结合起来时,问题就出现了
readline.question('network path: ', netPath => {
execSync(`net use ${netPath}`);
});
net use
将询问用户名,但
enter
必须命中两次