How to create bash shell using node-pty?

455 Views Asked by At

My OS is windows. I want to create a bash shell using xterm and node-pty. There is this line of code:

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

using which the terminal is rendered in browser. Now suppose if I write:

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

why isn't the bash shell getting rendered. It is giving me this error:

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...


Sorry for any mistakes in the question I am quite new to this...

1

There are 1 best solutions below

0
On

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.

Linux and windows run different types of programs. Bash was built for Linux.

Windows only runs file types such as .exe, .bat, .dll, etc. Bash doesn't have a file type. 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.

Your best bet is to enable WSL2 on your machine, or else download git Bash.