【问题标题】:How to create bash shell using node-pty?如何使用 node-pty 创建 bash shell?
【发布时间】:2021-06-29 07:45:08
【问题描述】:

我的操作系统是 windows。我想使用 xterm 和 node-pty 创建一个 bash shell。有这行代码:

this.shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';

终端在浏览器中呈现的方式。现在假设如果我写:

this.shell = os.platform() === 'win32' ? 'bash' : 'powershell.exe';
或者 this.shell = os.platform() === 'linux' ? 'powershell.exe' : 'bash';

为什么不渲染 bash shell。它给了我这个错误:

D:\DE_proj\linuxterminal\server\node_modules\node-pty\lib\windowsPtyAgent.js:75
            term = this._ptyNative.startProcess(file, cols, rows, debug, this._generatePipeName(), conptyInheritCursor);
                                   ^

Error: File not found:
    at new WindowsPtyAgent (D:\DE_proj\linuxterminal\server\node_modules\node-pty\lib\windowsPtyAgent.js:75:36)
    at new WindowsTerminal (D:\DE_proj\linuxterminal\server\node_modules\node-pty\lib\windowsTerminal.js:50:24)
    at Object.spawn (D:\DE_proj\linuxterminal\server\node_modules\node-pty\lib\index.js:28:12)
    at PTY.startPtyProcess (D:\DE_proj\linuxterminal\server\PTYService.js:16:27)
    at new PTY (D:\DE_proj\linuxterminal\server\PTYService.js:11:10)
    at Namespace.<anonymous> (D:\DE_proj\linuxterminal\server\SocketService.js:40:18)
    at Namespace.emit (events.js:315:20)
    at Namespace.emitReserved (D:\DE_proj\linuxterminal\server\node_modules\socket.io\dist\typed-events.js:56:22)
    at D:\DE_proj\linuxterminal\server\node_modules\socket.io\dist\namespace.js:140:26
    at processTicksAndRejections (internal/process/task_queues.js:75:11)
[nodemon] app crashed - waiting for file changes before starting...


抱歉问题中的任何错误我对此很陌生...

【问题讨论】:

  • 您似乎在 Windows 上,并且您似乎没有安装 Bash,或者至少没有在您的 PATH 中。还有什么要解释的?

标签: bash shell xtermjs node-pty


【解决方案1】:

Bash 不会在 Windows 上运行,除非您使用虚拟环境,例如 minTTY(如果您有 Git bash,那么您有一个功能齐全的 bash shell,但缺少一些功能),或者您安装了 WSL2。

Linux 和 Windows 运行不同类型的程序。 Bash 是为 Linux 构建的。

Windows 仅运行 .exe、.bat、.dll 等文件类型。Bash 没有文件类型。它们是一些可用的 3rd 方端口,但自从 Windows 发布 WSL2(它在 Windows 10 中创建 Linux shell)以来,它们的需求并不大。

最好的办法是在你的机器上启用 WSL2,或者下载 git Bash。

【讨论】:

    猜你喜欢
    • 2022-07-29
    • 1970-01-01
    • 2021-05-09
    • 1970-01-01
    • 1970-01-01
    • 2010-11-02
    • 1970-01-01
    • 2018-01-21
    相关资源
    最近更新 更多