简体   繁体   English

JScript / Windows Script Host 中的 UNIX `exec` 等价物

[英]Equivalent of UNIX `exec` in JScript / Windows Script Host

I've got a .js file that's meant to be executed by Node.js on the command-line.我有一个 .js 文件,它是由 Node.js 在命令行上执行的。 I've got everything set up with npm and such to put the file into the user's path as a "bin".我已经使用npm设置了所有内容,以便将文件作为“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.我的问题是,因为文件以 .js 结尾,所以从命令行运行它会将它传送到基于 JScript 的 Windows 脚本主机,而不是节点,正如预期的那样。

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.我正在尝试编写一个 JScript 包装器,位于myprogram.js ,由 Windows Script Host 执行,然后发送到 Node.js。 Unfortunately, it doesn't seem like WScript's Exec command behaves like the UNIX exec command:不幸的是,WScript 的Exec命令的行为似乎不像 UNIX exec 命令:

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.这会缓冲程序的输出,并通过某种 JScript WshScriptExec对象公开它。

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 (ie UNIX- exec -y behaviour.) Is there any way to do this, or some other way to solve my problem?最有用的是,我想用我正在执行的命令的进程(即 UNIX- exec -y 行为)替换正在执行的 JScript 进程。我的问题?

Avoid the .js suffix completely so you get the same unadorned command name, eg executable , on all platforms.完全避免使用 .js 后缀,以便在所有平台上获得相同的简单命令名称,例如executable

Do so by setting bin in package.json as follows and npm will sort it:通过如下在 package.json 中设置 bin 来实现,npm 将对其进行排序:

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

Source and further details: https://docs.npmjs.com/files/package.json#bin来源和更多详细信息: https : //docs.npmjs.com/files/package.json#bin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM