B
Bill Stewart
Hi all,
Suppose I have the following WSH 5.6 script (Test.js):
// START CODE
var tsinput = WScript.StdIn, tsoutput = WScript.StdOut;
while (! tsinput.AtEndOfStream)
tsoutput.WriteLine(tsinput.ReadLine());
// END CODE
All this script does is take each line of standard input and write it to
standard output. Suppose this script is saved as Test.js in the current
directory.
Why do I have to explicitly type "cscript" before the script name?
Cmd.exe shell session below:
C:\>type Test.js
var tsinput = WScript.StdIn, tsoutput = WScript.StdOut;
while (! tsinput.AtEndOfStream)
tsoutput.WriteLine(tsinput.ReadLine());
C:\>assoc .js
..js=JSFile
C:\>ftype JSFile
JSFile=%SystemRoot%\System32\CScript.exe "%1" %*
C:\>dir | Test.js
C:\Test.js(3, 1) (null): The handle is invalid.
C:\>dir | cscript Test.js
<output of dir command here>
....
C:\>_
This behavior is problematic because if Test.js doesn't sit in the
current directory, you have to specify its path.
It's almost like cmd.exe doesn't create the stdin and stdout streams
when executing a WSH script via its file association, even when CScript
is the default host (which is the case here).
Can anyone explain this behavior?
Thanks
Suppose I have the following WSH 5.6 script (Test.js):
// START CODE
var tsinput = WScript.StdIn, tsoutput = WScript.StdOut;
while (! tsinput.AtEndOfStream)
tsoutput.WriteLine(tsinput.ReadLine());
// END CODE
All this script does is take each line of standard input and write it to
standard output. Suppose this script is saved as Test.js in the current
directory.
Why do I have to explicitly type "cscript" before the script name?
Cmd.exe shell session below:
C:\>type Test.js
var tsinput = WScript.StdIn, tsoutput = WScript.StdOut;
while (! tsinput.AtEndOfStream)
tsoutput.WriteLine(tsinput.ReadLine());
C:\>assoc .js
..js=JSFile
C:\>ftype JSFile
JSFile=%SystemRoot%\System32\CScript.exe "%1" %*
C:\>dir | Test.js
C:\Test.js(3, 1) (null): The handle is invalid.
C:\>dir | cscript Test.js
<output of dir command here>
....
C:\>_
This behavior is problematic because if Test.js doesn't sit in the
current directory, you have to specify its path.
It's almost like cmd.exe doesn't create the stdin and stdout streams
when executing a WSH script via its file association, even when CScript
is the default host (which is the case here).
Can anyone explain this behavior?
Thanks