在JScript / Windows脚本主机中等效于UNIX`exec` [英] Equivalent of UNIX `exec` in JScript / Windows Script Host

查看:90
本文介绍了在JScript / Windows脚本主机中等效于UNIX`exec`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.js文件,该文件应由Node.js在命令行上执行。我已经使用 npm 进行了所有设置,并将文件作为 bin放入用户的路径。我的问题是,因为文件以.js结尾,所以从命令行运行该文件会将其传送到基于JScript的Windows Script Host,而不是按预期的方式传送到节点。

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.

我试图编写一个JScript包装器,位于 myprogram.js 处,由Windows Script Host执行,然后交付给Node.js。不幸的是,似乎WScript的 Exec 命令的行为不像UNIX exec命令:

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);

这将缓冲程序的输出,并通过某种JScript公开它。 WshScriptExec 对象。

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

我需要脚本,功能或其他某种方式来处理整个终端转到我正在启动的命令行脚本。最有用的是,我想将正在执行的JScript进程替换为我正在执行的命令的进程(即UNIX- exec -y行为)。有什么方法可以解决这个问题?

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?

推荐答案

完全避免使用.js后缀,这样您就可以相同的无修饰命令名称,例如在所有平台上都是可执行文件

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

通过在package.json中设置bin,如下所示,npm会对它进行排序:

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

{ bin :{可执行文件 : ./executable.js }}

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

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

这篇关于在JScript / Windows脚本主机中等效于UNIX`exec`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆