1

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?

4
  • That %ERRORLEVEL% is giving the exit status of the current command/script not the previous one. Commented Oct 5, 2015 at 7:14
  • That makes sense, what I would like to do is determine the exit code from the input stream and exit my app in a similar manner. Commented Oct 5, 2015 at 7:27
  • 1
    Check this stackoverflow.com/questions/11170753/… Commented Oct 5, 2015 at 7:29
  • 1
    This as well stackoverflow.com/questions/877639/… Commented Oct 5, 2015 at 7:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.