7

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.

2
  • 1
    You might have to use the start command to force open a new Command Prompt window. Commented Jul 31, 2015 at 3:54
  • @remus This is exactly what I want. I ever thought I know windows ^^. Do you coincidentally know equivalents to Linux and Mac? Commented Jul 31, 2015 at 4:07

1 Answer 1

18

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Is there any possibility to run this in background?
@YD_ Use child_process.exec() instead of child_process.execSync() to run the terminal in background.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.