Skip to content

Invoking command via Parser doesn't write to console, whereas command.Invoke does #2188

Closed
@maccsek

Description

@maccsek

I have a console application that uses System.CommandLine to parse arguments and options.

To be able to deal with exceptions better, I've switched from RootCommand.Invoke(args) to using a CommandLineBuilder in the way I saw discussed here in one of the earlier threads:

    CommandLineBuilder oCLB = new(oRootCmd);
    oCLB.UseExceptionHandler((e, c) => LogExceptionAndRaiseEvent(e));
    Parser oPrs = oCLB.Build();
    int iRC = oPrs.Invoke(p_StartupArgs);

Now I've noticed that this way of invoking doesn't write to the console anymore, neither when there is a parsing error nor when being called with the default help switch "-h".

I suspect it has to do with the second (IConsole) parameter in Invoke -- I've tried oPrs.Invoke(p_StartupArgs, new SystemConsole());, but without success. What am I missing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions