js中打开命令行窗口

js中打开命令行窗口

本文介绍了如何在Node.js中打开命令行窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何打开新的命令行窗口并执行在单独的独立进程中运行的bash命令?

How to open a new command line window and execute a bash command which runs in a separate independent process?

我尝试了

var child_process = require('child_process');
child_process.execSync("cmd.exe /K node my-new-script.js parm1 parm2);

但是它没有打开新窗口,我需要一个独立的进程(如果可能).背景是我正在尝试电子,并编写了一些节点命令行脚本.不幸的是,在电子环境中,产卵过程经常导致怪异的行为,而控制台日志的输出却很难看.

but it opens no new window and I need an independent process (if possible). The background is I am experimenting with electron and wrote some node command line scripts. Unfortunately within electron environment spawning processes results often in weird behavior and console log output is more than ugly.

顺便说一句,我需要的东西等同于OS X和Linux.

By the way I would need something equivalent to OS X and Linux.

推荐答案

对于Windows,您需要使用start命令:

For Windows, you'll need to use the start command:

start cmd.exe /K node my-new-script.js parm1 parm2

对于OS X,您可以使用:

For OS X, you can use:

osascript -e 'tell application "Terminal" to activate' -e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down'

对于其他* nix发行版,您需要查找它们,因为每个发行版都略有不同.

For other *nix distros, you'll need to look those up as each one is slightly different.

这篇关于如何在Node.js中打开命令行窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 08:37