Equivalent of UNIX `exec` in JScript / Windows Script Host
Asked Answered
S

1

0

I've got a .js file that's meant to be executed by Node.js on the command-line. I've got everything set up with npm and such to put the file into the user's path as a "bin". My problem is, because the file ends in .js, running it from the command line is shipping it off to the JScript-based Windows Script Host, instead of node, as expected.

I'm trying to write a JScript wrapper, to sit at myprogram.js, be executed by Windows Script Host, and ship off to Node.js. Unfortunately, it doesn't seem like WScript's Exec command behaves like the UNIX exec command:

var shell = new ActiveXObject("WScript.Shell");
var proc = shell.exec("node .\\Library\\executable.js");

while (proc.Status === 0) {
     WScript.Sleep(100);
}

WScript.Echo(proc.Status);

This buffers the program's output, and exposes it via some sort of JScript WshScriptExec object.

I need a script, or a feature, or some other way, to hand the entire terminal over to the command-line script I'm launching. Most usefully, I'd like to replace the JScript process that's executing, with the process for the command that I'm executing (i.e. UNIX-exec-y behaviour.) Is there any way to do this, or some other way to solve my problem?

Sarawak answered 9/6, 2014 at 2:58 Comment(3)
maybe this will be helpful #10396805Perlaperle
@wmz: yeah, that's all the stuff I've already discovered on my own. Problem is, it's not really an acceptable solution to rename a project, or to tell Windows users to use a different command name than everybody else in your documentation. Hence, trying to leverage Windows Script Host to solve my problem. /=Sarawak
AFAICT, there's not an exec equivalent on Windows that will work the way you want. See Is there a Windows CMD equivalent of Unix shell's exec?Melbourne
R
0

Avoid the .js suffix completely so you get the same unadorned command name, e.g. executable, on all platforms.

Do so by setting bin in package.json as follows and npm will sort it:

{ "bin" : { "executable" : "./executable.js" } }

Source and further details: https://docs.npmjs.com/files/package.json#bin

Resnatron answered 16/8, 2020 at 17:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.