【问题标题】:WSH (JScript) pass CLI arguments to another script that is activated internallyWSH (JScript) 将 CLI 参数传递给另一个在内部激活的脚本
【发布时间】:2015-08-17 12:10:05
【问题描述】:

所以我有我的JScript 脚本s1.js

var objArgs = WScript.Arguments;
WScript.Echo(objArgs.length)

s1.js 使用WSH 运行时 我得到了预期的WScript.Arguments

但是当我在内部运行s1.js 时,它变得很棘手。假设我有另一个脚本s2.js

var F = new Function(strScript); // strScript is the content of s1.js
(F)("test");

当运行s2.js 时,使用任何CLI 参数,s1.js 中定义的var objArgs = WScript.Arguments 得到与我传递给s2.js 相同的参数。

这并不让我感到惊讶,因为我假设 var objArgs = WScript.Arguments 是全局的并由 WSH 设置。

问题

  1. 如何激活s1.js(在s2.js 内部)并将CLI 参数传递给它?
  2. s1.js 如何区分两种不同的运行方式并正确读取其参数?

【问题讨论】:

    标签: javascript command-line-interface jscript wsh


    【解决方案1】:

    我不确定 WScript,但它似乎是所有 Js sn-ps 中的全局成员。我已经做了一些基本的测试,事实上,WScript.Arguments 在所有实例中都是相同的。问题的根源在于 new Function() 调用,因为前 N-1 个参数声明了参数模板,最后一个函数的主体。

    这是对我有帮助的答案 -> response

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-13
      • 1970-01-01
      • 1970-01-01
      • 2013-08-27
      • 1970-01-01
      • 1970-01-01
      • 2014-04-08
      • 1970-01-01
      相关资源
      最近更新 更多