【问题标题】:How can i open an interactive bash shell from nodejs REPL console如何从 nodejs REPL 控制台打开交互式 bash shell
【发布时间】:2017-08-31 20:26:09
【问题描述】:

我想从 nodejs 控制台打开一个 bash shell。

我已经尝试了 child_process 模块中的所有内容,但我没有设法找到可以看到 $ 提示符的解决方案。

谢谢

【问题讨论】:

    标签: node.js bash shell pipe sh


    【解决方案1】:

    您可以让孩子继承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

    【讨论】:

      猜你喜欢
      • 2020-08-31
      • 2020-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多