我给自己挖了一个很深的兔子洞,试图找出标题说的是什么。如果你对这个问题感到困惑,我会给出更详细的解释:你见过 VSCode 终端吗?还是终点站?嗯,我想做这些应用程序所做的事情。我有一个电子应用程序,为了方便用户,我想在其中包含某种命令提示符。我查看了 xterm.js,但只能找到 SSH 之类的示例,而不是到系统上托管的控制台的直接链接。 我要问的是如何将 xterm.js(在电子中)连接到真正工作的命令提示符?我见过能够与 cmd.exe 交互的程序,例如 Windows Terminal。我会用它作为例子。
在附图中您可以看到三个过程。 WindowsTerminal.exe、OpenConsole.exe 和 cmd.exe。在深入研究 Windows 终端的源代码后,我可以看到 OpenConsole.exe 随您创建的每个 cmd 实例一起启动。所以我假设这是与 cmd.exe 交互的程序。现在我知道Windows Terminal是使用UWP制作的,但是你可以看到类似的事情发生(我打开了一堆终端来演示)
这是另一篇带有“类似问题”的帖子,但没有答案。我希望这个能获得一些关注。 如果您能回答,谢谢。如果您有点偏离主题,请记住我的问题:
如何将 xterm.js(在电子中)连接到实际工作的命令提示符?抱歉,如果您无法理解我的措辞,我不太擅长:P
:
const os = require('os');
const pty = require('node-pty');
var shell = os.platform() === "win32" ? "powershell.exe" : "bash";
var ptyProcess = pty.spawn(shell, [], {
name: 'xterm-color',
cols: 80,
rows: 24,
cwd: process.env.HOME,
env: process.env
});
ptyProcess.on("data", (data) => {
mainWindow.webContents.send("terminal-incData", data);
});
ipcMain.on("terminal-into", (event, data)=> {
ptyProcess.write(data);
})
在渲染器进程中:
const Terminal = require('xterm').Terminal;
const FitAddon = require('xterm-addon-fit').FitAddon;
const term = new Terminal();
const fitAddon = new FitAddon();
term.loadAddon(fitAddon);
// Open the terminal in #terminal-container
term.open(document.getElementById('terminal-container'));
term.onData(e => {
ipcRenderer.send("terminal-into", e);
} );
ipcRenderer.on('terminal-incData', (event, data) => {
term.write(data);
})
// Make the terminal's size and geometry fit the size of #terminal-container
fitAddon.fit();
error: no template named 'remove_cv_t'
。gyp ERR! find Python
A JavaScript error occurred in the main process Uncaught Exception: Error: The module '/home/xyz/Downloads/electron-local-terminal-prototype-master/node_modules/node-pty/build/Release/pty.node' was compiled against a different Node.js version using NODE_MODULE_VERSION
64. This version of Node.js requires NODE_MODULE_VERSION 80. Please try re-compiling or re-installing the module (for instance, using `npm rebuild` or `npm install`). at process.func [as dlopen] (electron/js2c/asar.js:140:31) at Object.Module._extensions..node
(internal/modules/cjs/loader.js:1034:18) at Object.func [as .node] (electron/js2c/asar.js:140:31) at Module.load (internal/modules/cjs/loader.js:815:32) at Module._load (internal/modules/cjs/loader.js:727:14) at Function.Module._load (electron/js2c/asar.js:769:28)
at Module.require (internal/modules/cjs/loader.js:852:19) at require (internal/modules/cjs/helpers.js:74:18) at Object.
<anonymous> (/home/xyz/Downloads/electron-local-terminal-prototype-master/node_modules/node-pty/lib/unixTerminal.js:26:11) at Module._compile (internal/modules/cjs/loader.js:967:30) enter code here
我必须按照这个答案重建节点才能使其正常工作:https://stackoverflow.com/a/52796884