1

So I have my JScript script s1.js

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

when s1.js is run using WSH I get the expectedWScript.Arguments.

It gets tricky however when I run s1.js internally. Say I have another script s2.js:

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

When running s2.js, with whatever CLI argument, var objArgs = WScript.Arguments defined in s1.js get the same arguments I passed to s2.js.

This does not surprise me since I assume var objArgs = WScript.Arguments is global and set by WSH.

Question

  1. How do I activate s1.js (internally in s2.js) and pass CLI params to it?
  2. How do s1.js can distinguish between the two different ways of running it and read its arguments properly?
Community
  • 1
  • 1
idanshmu
  • 5,061
  • 6
  • 46
  • 92

1 Answers1

1

I'm not sure about WScript, but it seems like it's a global member among all Js snippets. I've done some basic tests and in-fact, WScript.Arguments is identical among all instances. The root for your problems lays within the new Function() call, As the first N-1 parameters declare the template for parameters, and the last one function's body.

Here's the answer that helped me -> response

Community
  • 1
  • 1
igal k
  • 1,883
  • 2
  • 28
  • 57