07-23-2023, 10:51 AM
Considering pipes in Windows command shell cmd.exe:
C:\>feed | filter
The standard output from the feeding process doesn't seem to reach the standard input of the filtering process until AFTER the feeding process runs to completion.
This type of 'buffering' can cause annoying delays in output messages for long running feeding processes (where you might want to hit 'ctrl-c' to interrupt it on early failure).
Is there a way to avoid this so that standard output from the feeding process reaches standard input on the filtering process as soon as data is available? (no 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
)
The below command doesn't display anything until after 3 seconds (when the sleep completes):
C:\>feed | filter
_something
_something else
The desired behavior would be that '_something' is printed, followed by a 3 second delay, followed by '_something else' being printed.
C:\>feed | filter
The standard output from the feeding process doesn't seem to reach the standard input of the filtering process until AFTER the feeding process runs to completion.
This type of 'buffering' can cause annoying delays in output messages for long running feeding processes (where you might want to hit 'ctrl-c' to interrupt it on early failure).
Is there a way to avoid this so that standard output from the feeding process reaches standard input on the filtering process as soon as data is available? (no 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
)
The below command doesn't display anything until after 3 seconds (when the sleep completes):
C:\>feed | filter
_something
_something else
The desired behavior would be that '_something' is printed, followed by a 3 second delay, followed by '_something else' being printed.