简体   繁体   English

如何使用 node-pty 创建 bash shell?

[英]How to create bash shell using node-pty?

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

this.shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';<\/code>

使用哪个终端在浏览器中呈现。现在假设如果我写:

this.shell = os.platform() === 'win32' ? 'bash' : 'powershell.exe';<\/code>
还是this.shell = os.platform() === 'linux' ? 'powershell.exe' : 'bash';<\/code>

为什么 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...


Bash will not run on windows, unless you either use a virtual environment such as minTTY (if you have Git bash, you have a fully functional bash shell minus a couple features), or you install WSL2. Bash 不会在 Windows 上运行,除非您使用诸如 minTTY 之类的虚拟环境(如果您有 Git bash,则您有一个功能齐全的 bash shell 减去一些功能),或者您安装 WSL2。

Linux and windows run different types of programs. Linux 和 Windows 运行不同类型的程序。 Bash was built for Linux. Bash 是为 Linux 构建的。

Windows only runs file types such as .exe, .bat, .dll, etc. Bash doesn't have a file type. Windows 仅运行 .exe、.bat、.dll 等文件类型。Bash 没有文件类型。 Their are a few 3rd party ports available, but ever since Windows released WSL2, which creates Linux shells inside Windows 10, their isn't much of a demand.它们是一些可用的 3rd 方端口,但自从 Windows 发布 WSL2(它在 Windows 10 中创建 Linux shell)以来,它们的需求并不大。

Your best bet is to enable WSL2 on your machine, or else download git Bash.最好的办法是在你的机器上启用 WSL2,或者下载 git Bash。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM