2

I have a WPF application that takes command line arguments and in some cases returns an exit value without starting the App. I have replaced the entry point as in this question Replacing the WPF entry point. When I run in Visual Studio without an argument it launches my App as expected. When I supply an argument it all looks good I get a line telling me "The program XXX has exited with code 66"

When I then run from the CMD command line without an argument it launches the app as expected. When I supply an argument and look at %ERRORLEVEL% I get an exit code of 0 not 66. What gives here ?

namespace WpfApplication2
{

  public class EntryPoint
  {
    [STAThread]
    public static void Main(string[] args)
    {
            if (args.Count > 0)
            {
                Environment.Exit(66);
            }
            App.Main();
    }
  }

  public partial class App : Application
  {
  }
}
1
  • I created a quick c# console app to call the app using Process.Start and report the exit code and it correctly reported an exit code of 66 when I run my app with an argument. So purely something wrong on command line. Commented Aug 27, 2015 at 7:54

1 Answer 1

3

Your application is windowed, and runs in the background as far as the command window is concerned, so %errorlevel% only shows that the application was launched. When your application later exits, the exit code is lost.

As described in https://stackoverflow.com/a/11476681, if you launch your application with START /WAIT, then the command window will wait for your application to exit and store the exit code in %errorlevel%.

Sign up to request clarification or add additional context in comments.

Comments

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.