Equivalent of UNIX `exec` in JScript / Windows Script Host

笑着哭i 提交于 2019-12-25 02:29:32

问题


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?

来源:https://stackoverflow.com/questions/24113091/equivalent-of-unix-exec-in-jscript-windows-script-host

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!