【问题标题】:I want to run the terminal command n nodejs language我想用 node js 语言运行终端命令
【发布时间】:2020-05-04 09:06:44
【问题描述】:

创建一个Nodejs服务器代码,我想打开一个新的终端窗口并输入一个命令。

var exec = require('child_process').exec

exec('gnome.terminal', (err,out,stderr) => {
console.log(out)
});`

我想用上面的代码打开一个新窗口并输入一个命令。

(new) 1 terminal -> command : roslaunch rpliadr_ros rplidar.launch
(new) 2 terminal -> command : roslaunch hector_slam_launch tutorial.launch 

【问题讨论】:

    标签: node.js exec


    【解决方案1】:

    请查找shell.js模块。

    【讨论】:

      【解决方案2】:

      您可以使用OpenTerm 模块。这正是你想要的——打开终端,然后执行。

      它对单个终端具有两种功能:(仅当您确定它们存在于您的 PATH 中时才考虑使用它们)。

      const { VT } = require('open-term')
      VT.linux.xterm('ls -l') // Runs "ls -l" command in xterm.
      VT.linux.guake('ls -l') // Runs "ls -l" command in guake.
      

      以及自动确定要使用的终端的可配置功能:

      const { VTexec } = require('open-term')
      VTexec('help') // "help" command works both on bash and cmd.
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-12-22
        • 1970-01-01
        • 1970-01-01
        • 2011-10-17
        • 1970-01-01
        • 2018-12-28
        • 2018-06-19
        • 1970-01-01
        相关资源
        最近更新 更多