简体   繁体   English

如何不使用 node-pty 和 xterm 在终端中打印命令?

[英]How do I not print a command in the terminal using node-pty and xterm?

I'm using xterm.js, node-pty, and electron to build a node repl like terminal (similar to repl.it).我正在使用 xterm.js、node-pty 和电子来构建像终端一样的节点 repl(类似于 repl.it)。 I'm using this piece of code to run the file and output it to the terminal:我正在使用这段代码来运行文件并将其输出到终端:

ptyProcess.write("vm.runInNewContext(fs.readFileSync('dir/file.js', 'utf8'))\\r")

But I always get this printed to the terminal:但我总是把它打印到终端:

> vm.runInNewContext(fs.readFileSync('dir/file.js', 'utf8'))
5
>

I know ptyProcess.write() writes to the terminal, but is there a way to run a command without printing it to the terminal?我知道ptyProcess.write()写入终端,但是有没有办法运行命令而不将其打印到终端? How can I get the terminal to print something like this:我怎样才能让终端打印这样的东西:

>
5
>

use ptyProcess.on('data', function(data){}) to filter data使用ptyProcess.on('data', function(data){})过滤数据

xterm.js docs link: onevent-callback xterm.js 文档链接: onevent-callback

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

相关问题 如何在 Electron 中使用 node-pty 正确启动 shell 环境? - How do I correctly launch a shell environment with node-pty in Electron? 在电子锻造项目中安装“node-pty”后,缺少名为 pty.node.js 的文件。 如何在 Linux 中安装 node-pty - A file called pty.node.js is missing after installing "node-pty" in a electron-forge project. How can I install node-pty in Linux Node JS - 退格在 Node-Pty 终端中不起作用 - Node JS - Backspace not working in Node-Pty Terminal 如何通过node-pty设置$ PATH作为在节点中扩展进程的一部分? - How can I set $PATH as part of spawing a process in node via node-pty? 如何从命令行(终端)使用节点访问模块 - How do I access a module using a node from the command line(terminal) 在终端中运行JavaScript(使用Rhino)时,如何使用print()函数在一行中打印? - While running JavaScript in Terminal (using rhino) how do I print in a single line using print() function? 如何使process.argv仅输出参数(而不输出路径或节点命令) - How do I make process.argv print only the arguments (and not the path or node command) 如何将节点缓冲区打印为二进制文件? - How do I print a node Buffer as binary? 单击按钮并发送命令以在 xterm.js 终端上执行 - Click button and send command to execute on xterm.js terminal 如何在jquery终端中解析命令参数? - How do I parse command arguments in jquery terminal?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM