【发布时间】:2017-08-31 20:26:09
【问题描述】:
我想从 nodejs 控制台打开一个 bash shell。
我已经尝试了 child_process 模块中的所有内容,但我没有设法找到可以看到 $ 提示符的解决方案。
谢谢
【问题讨论】:
标签: node.js bash shell pipe sh
我想从 nodejs 控制台打开一个 bash shell。
我已经尝试了 child_process 模块中的所有内容,但我没有设法找到可以看到 $ 提示符的解决方案。
谢谢
【问题讨论】:
标签: node.js bash shell pipe sh
您可以让孩子继承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 替换为适合您平台要求的正确shell
【讨论】: