Run console application from other console app

前端 未结 6 1962
耶瑟儿~
耶瑟儿~ 2020-12-02 18:40

I have a C# console application (A). I want to execute other console app (B) from within app A (in synchronous manner) in such way that B uses the same command window. When

6条回答
  •  忘掉有多难
    2020-12-02 19:20

    I was able to run the program 'B' as part of the same command window by calling the following configuration:

    ConsoleColor color = Console.ForegroundColor;
    ProcessStartInfo startinfo = new ProcessStartInfo(nameProgramB);
    startinfo.CreateNoWindow = false;
    startinfo.UseShellExecute = false;
    Process p = Process.Start(startinfo);
    p.WaitForExit();
    Console.ForegroundColor = color;
    

    this way, both programs run seamlesly like they were one single program. 'nameProgramB' is the name to program 'B'. Hope this helps.

提交回复
热议问题