Piping Cscript.exe to HEAD?

May 20, 2008
12,164
131
Syracuse, NY, USA
Is there any way to get rid if this message from Cscript.exe?

Code:
v:\> cscript //nologo services3.btm:GetInfo.vbs | head /n4
Appinfo
6092
Application Information
20191031225719.238579-240
v:\services3.btm:GetInfo.vbs(6, 2) (null): The pipe is being closed.

Cscript has this option

Code:
//B         Batch mode: Suppresses script errors and prompts from displaying

but that suppresses all output.
 
When I run;
Code:
cscript //nologo vince.vbs  | wsl head
under TCC, CMD, PowerShell (all 64-bit), I get;
TCC E:\Utils\vince.vbs(16, 5) (null): The pipe is being closed.
CMD e:\utils\vince.vbs(16, 5) (null): The pipe is being closed.
PowerShell ** There is no error generated **
pshell /s "cscript //nologo vince.vbs | wsl head" ** There is no error generated **

What is PowerShell doing that does not return the error?

Joe
 
May 20, 2008
12,164
131
Syracuse, NY, USA
Beats me!

Another PowerShell anomaly ... everywhere it the registry that I found a cscript.exe command line, I added //NoLogo. Having done that, when I run a .VBS in TCC or CMD, by name, (e.g., simply MyWMIQuery.vbs) I don't get the logo. In PowerShell I still get the logo.

Code:
c:\users\vefatica\desktop> MyWMIQuery.vbs | head /n3
6092
Appinfo
Application Information
C:\Users\vefatica\Desktop\MyWMIQuery.vbs(13, 9) (null): The pipe is being closed.


c:\users\vefatica\desktop> cmd /c MyWMIQuery.vbs ^| head -n 3

6092
Appinfo
Application Information
C:\Users\vefatica\Desktop\MyWMIQuery.vbs(13, 9) (null): The pipe is being closed.

c:\users\vefatica\desktop> pshell /s ".\MyWMIQuery.vbs | wsl head"
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

6092
Appinfo
Application Information
20191031225719.238579-240
1932
AudioEndpointBuilder
Windows Audio Endpoint Builder
 
Hey @vefatica,
It would seem that piping to head is giving "The pipe is being closed." message.

The following do not give that message;
Code:
cscript //nologo vince.vbs | tail
cscript //nologo vince.vbs | echo %@lines[con]

If I run the .vbs with HEAD /N800, that is, more lines than the output, there is no message.

Also, I can run any other .vbs, pipe it to head, and not receive the message.

This includes any .vbs files where I am also doing an .ExecQuery

Joe
 
May 20, 2008
12,164
131
Syracuse, NY, USA
It has something to do with the amount of (would-be) output (and then maybe with the buffering, or lack thereof) of stdout.

Reliably, this (4224 characters of would-be output) does not give the error message when piped to HEAD.

Code:
For x = 1 to 352
    Wscript.Echo "xxxxxxxxxx"
Next

And this (4236 characters) does give the error message.

Code:
For x = 1 to 353
    Wscript.Echo "xxxxxxxxxx"
Next
 
May 20, 2008
12,164
131
Syracuse, NY, USA
Under CMD, the difference happens at 386/387 (4632/4644 characters).

Powershell seems to do things differently. With "For x = 1 to 1000000" Powershell takes 15 seconds before printing the 10 lines (not closing the pipe when HEAD exits???) while TCC and CMD show the output immediately.

With CMD and Powershell, I was using Gnu's HEAD.EXE (for Windows). It's the same with wsl head.
 
May 20, 2008
12,164
131
Syracuse, NY, USA
And doing the whole thing under WSL, the difference (error/no error) is still somewhere between 300 and 400 iterations, but the error message is different. No surprise I guess; there must be some trickery going on with such a mixture of Linux and Windows.

Code:
c:\users\vefatica\desktop> wsl cscript.exe /nologo c:\\Users\\vefatica\\Desktop\\1234.vbs ^| head -n 5
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
c:\Users\vefatica\Desktop\1234.vbs(2, 2) (null): The specified network name is no longer available.
 

Similar threads