在Node中,如何用子进程模块完成一个有交互的命令?
Node中的子进程模块可以输入一些shell命令来完成一些事情 比如查看当前目录的文件: screenshot.png 但如果有一个命令需要执行后再次输入比如密码之类的子命令,应该如何通过该模块实现?或者不通过该模块如何实现?
5 回复
const child_process = require('child_process');
const c = child_process.spawn('cmd');
c.stdout.on('data', data => console.log(`###cmd###\n${data.toString()}\n#########`));
c.stdin.write('echo hello world\n');