A
Alex K. Angelopoulos [Server MVP]
I'm working on a standard way to allow argument-vs-input stream selection
for console-mode WSH scripts, and would like some opinions about the best
way to proceed with them.
I've finally rejected the idea of automatically redirecting to stdin in the
absence of unnamed arguments due to how often it makes sense to use a
default value of some kind (for example, getting uptime - no args or input
would mean get it from the local system usually. On the other hand, you may
want to check uptime data for an entire list of remote systems, in which
case you want to read them from stdin).
I'm now using a strategy of checking for a null named argument, which would
be submitted on the commandline as just a solidus (/) with nothing following
it. This allows making it a "named argument" analogous to the Unix "-"
option name used for redirection of input.
I also drop all unnamed arguments which could be considered input data if
stdin is being read. This seems to me to be the most logical way to handle
things, but I'd like to get some feedback from other people using
commandline tools and stdin streams about whether it makes sense to do it
this way.
Any opinions? WSF content I use for this follows...
====================
Implementation Info
For example, here's how the option would be specified in the <runtime>
element - note the embedded backspace character (0x08) which forces display
of a single "/" in the usage help:
<named name="/" helpstring="causes data to be read from stdin; each line is
interpreted as a separate script name." required="false" type="simple"/>
Within VBScript code, the actual test would look like this:
If WScript.Arguments.Named.Exists(vbNullString) Then
Do While Not WScript.StdIn.AtEndofStream
Main WScript.StdIn.ReadLine
Loop
Else
For Each arg in WScript.Arguments.UnNamed
Main arg
Next
End If
for console-mode WSH scripts, and would like some opinions about the best
way to proceed with them.
I've finally rejected the idea of automatically redirecting to stdin in the
absence of unnamed arguments due to how often it makes sense to use a
default value of some kind (for example, getting uptime - no args or input
would mean get it from the local system usually. On the other hand, you may
want to check uptime data for an entire list of remote systems, in which
case you want to read them from stdin).
I'm now using a strategy of checking for a null named argument, which would
be submitted on the commandline as just a solidus (/) with nothing following
it. This allows making it a "named argument" analogous to the Unix "-"
option name used for redirection of input.
I also drop all unnamed arguments which could be considered input data if
stdin is being read. This seems to me to be the most logical way to handle
things, but I'd like to get some feedback from other people using
commandline tools and stdin streams about whether it makes sense to do it
this way.
Any opinions? WSF content I use for this follows...
====================
Implementation Info
For example, here's how the option would be specified in the <runtime>
element - note the embedded backspace character (0x08) which forces display
of a single "/" in the usage help:
<named name="/" helpstring="causes data to be read from stdin; each line is
interpreted as a separate script name." required="false" type="simple"/>
Within VBScript code, the actual test would look like this:
If WScript.Arguments.Named.Exists(vbNullString) Then
Do While Not WScript.StdIn.AtEndofStream
Main WScript.StdIn.ReadLine
Loop
Else
For Each arg in WScript.Arguments.UnNamed
Main arg
Next
End If