0

On clicking a button, I want to run a node file main.js on cmd terminal.

I did:

var ip ="f:\ node main.js ";

function pingItjs(ip) {
    var oShell = new ActiveXObject("wscript.shell"); 
    oShell.run("cmd.exe /k" + ip); 
}

but it only opens a cmd with F:\ drive and doesn't append the command:

node main.js

How can I do that?

1 Answer 1

1

There is this library that does exactly that :) called node-cmd. But you have to use this inside NodeJS.

With pure JS (without NodeJS), I'd do something like this:

// Instantiate the Shell object and invoke its execute method.
var oShell = new ActiveXObject("Shell.Application");

var commandtoRun = "f:\ node main.js ";

// Invoke the execute method.  
oShell.ShellExecute(commandtoRun, "", "", "open", "1");
Sign up to request clarification or add additional context in comments.

Comments

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.