我想从nodejs console打开一个bash shell。
我尝试了Child_process模块中的所有内容,但是我没有设法找到可以看到$提示的解决方案。
谢谢
您可以使孩子继承stdio
,在这里您有一个工作示例(linux):
const { spawn } = require('child_process')
const shell = spawn('sh',[], { stdio: 'inherit' })
shell.on('close',(code)=>{console.log('[shell] terminated :',code)})
示例输出:
sh-4.4$ uname
Linux
sh-4.4$ exit
exit
[shell] terminated : 0
请记住将sh
替换为您的平台要求