I have a console application written in c# which reads characters from Console.In
, parses the characters and output the results to the Console.Out
. It works fine except when the input is pipes in from another console command and that command exits with a code other than 0
in this case the exit code is always 0
.
For example using the TestCommand.cmd script:
@echo off
echo Plain text
exit /b 1
Running this script give the following output:
>TestCommand.cmd
Plain text
>echo %ERRORLEVEL%
1
If I pipe the output to my console app I get a exit code 0
>TestCommand.cmd | MyConsoleApp.exe
Plain text
>echo %ERRORLEVEL%
0
Is it possible to determine the exit code from the "up stream" input in .Net and exit my app with the same code?
It would be acceptable even just to determine that it exited with a code != 0?
Preferably .Net 2?