所以,我想做一些设置并创建一个环境来使用节点运行各种命令。在 python 中或从 shell 中执行此操作很简单(也许这是最好的答案),但由于各种原因,使用 node 具有优势。我尝试了各种不同的 spawn 排列,但一切都以不同的方式失败。这可能是我得到的最接近的。
$ node
> const { spawn } = require('child_process');
undefined
> const ignore = spawn('/bin/zsh', ['--no-rcs'],
{ stdio:'inherit', detached: true, env: {...process.env, 'PS1': 'Subshell> ' }}
).on('code', () => console.log('done'))
undefined
> %
Subshell> ls
Thrown:
ReferenceError: l is not defined
>sls
zsh: command not found: sl
Subshell>
但是,并没有那么接近。