Does the pipeline in Windows cmd.exe not transfer standard output until the process completes?

Examination of pipes in the Windows shell cmd.exe:

C:\>feed | filter

The standard exit from the feed process does not seem to reach the standard input of the filter process until AFTER the feed process is completed.

This type of "buffering" can cause annoying delays in the output messages for lengthy feed processes (where you can press "ctrl-c" to abort it in case of an early error).

Is there a way to avoid this so that the standard output from the feed process reaches the standard input in the filtering process as soon as the data is available? (without buffering)

For example, the following simplified example:

feed.bat:

@echo off
echo something
sleep 3
echo something else

filter.bat:

@echo off
for /F "tokens=*" %%a in ('more') do (
    echo _%%a
)

, 3 ( ):

C:\>feed | filter
_something
_something else

, "_something", 3- , "_something else".

+3
1

Windows cmd.exe. . .

1) FOR/F , IN() . FOR/F. IN() .

, filter.bat .

2) MORE - ​​, stdout. ( ).

- , , stdin stdout.


FEED.BAT - ​​ . .

@echo off
echo something
timeout /nobreak 3 >nul
echo something else
timeout /nobreak 3 >nul
for /l %%N in (1 1 3) do (
  <nul set /p "=%%N"
  timeout /nobreak 3 >nul
)
echo(
echo Done

FILTER.JS - stdin stdout, .

while (!WScript.StdIn.AtEndOfStream) WScript.Stdout.Write(WScript.StdIn.Read(1));

feed | cscript //nologo filter.js

, <pause> , .

something
<pause>something else
1<pause>2<pause>3<pause>
Done

, ( ).

/ . , . , . . , , , .

, Windows. , ? .

+4

All Articles