run console application in C# with parameters

前端 未结 6 1859
隐瞒了意图╮
隐瞒了意图╮ 2020-12-11 02:31

How can I run a console application in C#, passing parameters to it, and get the result of the application in Unicode? Console.WriteLine is used in the console

6条回答
  •  半阙折子戏
    2020-12-11 03:19

    Check out Process.Start():

    MSDN - Process.Start Method

    Your code will probably look something like:

    var process = Process.Start(pathToProgram, argsString);
    
    process.WaitForExit();
    
    var exitCode = process.ExitCode;
    

    If by "result of the console application" you mean any output of the program to the console while it runs...you'll need to look at the documentation and figure out how to redirect the output of the program from the console to another stream.

提交回复
热议问题