Jump to content of transcoded page.

This is a text-only page produced by the demo version of Usablenet Assistive: the actual content starts below this notice. For more details go to Lift Assistive Help Center.

javascript code to use WScript parameters

The following code makes use of the WScript.Arguments.Named and Unnamed properties to retrieve and use the WshNamed and WshUnnamed objects.

You can find something on MSDN about this topic, but this is a useful and till-now-missing example (IMHO).

For example, call it with “cscript /Nologo libparam.js /debug bla=bla key=value /verbose”.

var argsNamed = WScript.Arguments.Named;
var argsUnnamed = WScript.Arguments.Unnamed;

function Parameters (argumentsNamed, argumentsUnnamed, splitCharacter) {
    this.splitChar = splitCharacter;
	this.named = argumentsNamed;
    this.unnamed = argumentsUnnamed;
	this.unnamedOptions = new Array()

	this.decomposeUnnamedOptions = function ()
	{
		if (typeof(this.unnamed) == 'undefined')
			return
		//WScript.Echo("this.unnamed.length: " + this.unnamed.length);
		for (var j = 0; j  2)
				continue;
			if(typeof(parts[1]) == 'undefined')
				this.unnamedOptions[parts[0]] = 'undefined';
			this.unnamedOptions[parts[0]] = parts[1];
		}
	}

	this.debug = function () {
		WScript.Echo("Parameters class inited.");
		WScript.Echo("There are " + this.named.length + " named arguments.");
		WScript.Echo("There are " + this.unnamed.length + " unnamed arguments.");
		WScript.Echo("The split character is '" + this.splitChar + "'");
		WScript.Echo("The named args are "+this.named.length+" :");
		for (var j in this.named) {
			WScript.Echo("named(" + j+"):"+this.named.Item(j));
		}
		WScript.Echo("The unnamed args are "+this.unnamed.length+" :");
		for (var j = 0; j < this.unnamed.length; j = j + 1) {
			WScript.Echo("unnamed(" + j+"):"+this.unnamed.Item(j));
		}
	}

}

params = new Parameters(argsNamed, argsUnnamed, "=");

params.decomposeUnnamedOptions();

if (params.named.Exists("debug"))
	params.debug();

if (params.named.Exists("verbose"))
	WScript.Echo("---begin processing unnamed args");

if (!params.named.Exists("noresults")) {
	for (var i in params.unnamedOptions) {
		WScript.Echo('key is: ' + i + ', value is: ' + params.unnamedOptions[i]);
	}
}

if (params.named.Exists("verbose"))
	WScript.Echo("---end processing unnamed args");

Permalink

1 Comment »

  1. Ivo said,

    27 August 2008 @ 15:01

    perdincibaccoliona! wordpress re-formats the preformatted….

RSS feed for comments on this post · TrackBack URI

Leave a Comment

You must be logged in to post a comment.

Text Only Options

Top of page


Text Only Options

Open the original version of this page.

     

Usablenet Assistive is a UsableNet product. Usablenet Assistive Main Page.