Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a command line window in Node.js?

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

I tried

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.

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

like image 746
Stephan Ahlf Avatar asked Jul 31 '15 03:07

Stephan Ahlf


People also ask

How do I open a command prompt in JavaScript?

var objShell = new ActiveXObject("Shell. Application"); objShell. ShellExecute("cmd.exe", "C: cd C:\\pr main.exe blablafile. txt auto", "C:\\WINDOWS\\system32", "open", "1");

How do you get to a CLI window?

Opening: WindowsGo to Start menu → Windows System → Command Prompt. Go to Start menu → All Programs → Accessories → Command Prompt. Go to the Start screen, hover your mouse in the lower-left corner of the screen, and click the down arrow that appears (on a touch screen, instead flick up from the bottom of the screen).

What is node js command prompt?

It is a computer environment the same as command prompt and an easy way to test simple Node. js/JavaScript code and allows to execute multiple javascript codes. we can simply run REPL on the command prompt using node command on the command prompt.

How do I open a command window from the terminal?

Press Windows+R to open “Run” box. Type “cmd” and then click “OK” to open a regular Command Prompt. Type “cmd” and then press Ctrl+Shift+Enter to open an administrator Command Prompt.


1 Answers

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

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

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'

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

like image 75
brandonscript Avatar answered Sep 23 '22 01:09

brandonscript