[英]How can i open an interactive bash shell from nodejs REPL console
I want to open a bash shell from nodejs console. 我想从nodejs控制台打开一个bash shell。
I have tried everything from child_process module, but i did not managed to find a solution where i can see $ prompt. 我已经尝试过child_process模块的所有操作,但是我没有设法找到可以看到$提示符的解决方案。
Thanks 谢谢
You can make the child inherit the stdio
, here you have a working example (Linux) : 您可以让孩子继承
stdio
,这里有一个有效的示例(Linux):
const { spawn } = require('child_process')
const shell = spawn('sh',[], { stdio: 'inherit' })
shell.on('close',(code)=>{console.log('[shell] terminated :',code)})
example output : 示例输出:
sh-4.4$ uname
Linux
sh-4.4$ exit
exit
[shell] terminated : 0
Remember to replace sh
with the correct shell for your platform requirements 切记使用适合您平台要求的正确外壳替换
sh
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.