2

I am using Command Line Parser Library for C# console application. How I can retreive error messages if error occurs?

The use case is that this console app will be called from some another app and I want to provide to that app error message if some error occurs.

Here is a code snippet for parsing:

var options = new Options();
if (!CommandLine.Parser.Default.ParseArguments(args, options))
{
    string errorMessage = ExctractParsingErrors();
    GenerateErrorInvalidArguments(errorMessage);
    Environment.Exit(CommandLine.Parser.DefaultExitCodeFail);
}

Inside function ExctractParsingErrors() I have to extract parsing error. Example output of that function could be "-i/--input required option is missing."

Any idea how I could manage to extract parsing errors?

gandra404
  • 5,727
  • 10
  • 52
  • 76
  • Show how you invoke the executable. If it's Process.Start(), it's really trivial to capture the standard and error output. Try searching. – CodeCaster Aug 03 '15 at 14:35
  • I want to leave error info in some file if it is possible. So question remains if it is possible to extract explicitly parsing error in command line to persist error info in some file. – gandra404 Aug 03 '15 at 14:38
  • You say _"this console app (A) will be called from some another app (B) and I want to provide to that app (B?) error message if some error occurs"_. You can do so by reading the standard and error output of app A from app B. – CodeCaster Aug 03 '15 at 14:55

1 Answers1

0

There is an additional overload that allows you to pass a TextWriter helpWriter, according to the documentation of the component you linked.

Mark Jansen
  • 1,491
  • 12
  • 24
  • 1
    I can import ICommandLineParser ... eventually documentation is not accurate? Here is a screenshot of Object Browser: http://i.imgur.com/obit3Jf.png – gandra404 Aug 03 '15 at 15:38