When having a text file test.txt
containing this1:
test data
The following code returns the content of the text file with the first character removed:
< "test.txt" (
> nul pause
findstr "^"
)
The same happens when using a pipe:
type "test.txt" | (
> nul pause
findstr "^"
)
Because the pause
command takes exactly one character.
However, when replacing the pause
command by either of the following commands, the output is empty, although – like pause
– they prompt (/W
) for a single character only:
2> nul xcopy /W ? .
replace /W /U ? .
Why is this, what happens here?
Are xcopy /W
and replace /W
consuming all redirected/piped text data, even multiple lines, although they display only the first character they receive? Are they messing around with the file pointer?
Is there a way to prevent these commands from absorbing more than a single character?
1… With the last line terminated by a line-break in order for findstr
not to hang indefinitely – see this thread: What are the undocumented features and limitations of the Windows FINDSTR command?, section »FINDSTR hangs on XP and Windows 7 if redirected input does not end with <LF>
«.