There seem to be 4 predefined streams
0 stdIn
1 stdOut
2 stdErr
3 incoming file stream
____________________________________________________
You could display the stream numbers 0 and 1
*.bat
Code: Select all
@prompt $g$s
>xyz.txt echo(
<xyz.txt more +1
@echo off
del xyz.txt
pause>nul
Output:
Code: Select all
> echo( 1>xyz.txt
> more +1 0<xyz.txt
You will find the 1 in the first line and 0 in the second line even if they were not parts of the code.
____________________________________________________
You could redirect other streams to stdOut.
dir :... produces two different streams at the same time: stdOut and stdErr (where
Datei nicht gefunden ~>
file not found)
Note that only stdOut can be piped (|) to another command...
*.bat
Code: Select all
@prompt $g$s &cd /d C:\
@echo This is the line I'd like to play with:
dir :
@echo(
@pause
@echo(--------------------------------------------
dir : |findstr .
@echo(
@pause
@echo(--------------------------------------------
dir : 2>&1 |findstr .
@echo(
@pause
@echo(--------------------------------------------
dir : 2>&1 >nul |findstr .
@echo(
@pause
Output:
Code: Select all
This is the line I'd like to play with:
> dir :
Volume in Laufwerk C: hat keine Bezeichnung.
Volumeseriennummer: 9EA9-0A00
Verzeichnis von C:\
Datei nicht gefunden
Drücken Sie eine beliebige Taste . . .
--------------------------------------------
> dir : | findstr .
Datei nicht gefunden
Volume in Laufwerk C: hat keine Bezeichnung.
Volumeseriennummer: 9EA9-0A00
Verzeichnis von C:\
Drücken Sie eine beliebige Taste . . .
--------------------------------------------
> dir : 2>&1 | findstr .
Volume in Laufwerk C: hat keine Bezeichnung.
Volumeseriennummer: 9EA9-0A00
Verzeichnis von C:\
Datei nicht gefunden
Drücken Sie eine beliebige Taste . . .
--------------------------------------------
> dir : 2>&1 1>nul | findstr .
Datei nicht gefunden
Drücken Sie eine beliebige Taste . . .
The first section shows the entire output.
The 2nd section displays the stdErr first while the stdOut is piped to FINDSTR and appears later.
In the 3rd section stdOut and stdErr are merged and both are piped to FINDSTR (that removes the blank lines).
The 4th section is a bit tricky to understand. It's written opposite, but the redirections are processed:
- first stdOut to NUL
- then stdErr to stdOut
As you can see the former stdErr is now the stdOut and can be piped to FINDSTR.
____________________________________________________
You can redirect to stream 3 only if it was not used. Otherwise an error occurs.
dummy.txt
test.bat
Code: Select all
@echo off
echo(>&3
set /p "var=file input?"
echo("%var%"
echo ------------------------------------------------------
called from the command prompt
Code: Select all
> rem Without file redirection:
> test.bat
file input?
""
------------------------------------------------------
> rem With file redirection:
> test.bat<dummy.txt
Das System kann nicht auf das angegebene Gerät schreiben.
file input?"1st line in dummy.txt"
------------------------------------------------------
>
... where
Das System kann nicht auf das angegebene Gerät schreiben. ~>
The system cannot write to the specified device.Hope that helps.
Regards
aGerman