Is there a way to create a second console to output to in .NET when writing a console application?

后端 未结 3 1022
礼貌的吻别
礼貌的吻别 2020-12-02 21:10

Is there a way to create a second console to output to in .NET when writing a console application?

3条回答
  •  忘掉有多难
    2020-12-02 21:43

    The following fires off an application-dependent number of console windows and stores the amount and parameters for the console inside a String Dictionary that is then looped to generate the required amount of spawned console apps. You would only need the process stuff if only spawning one of course.

    //Start looping dic recs and firing console
    foreach (DictionaryEntry tests in steps)
    {
        try
        {
            Process runCmd = new Process();
            runCmd.StartInfo.FileName = CONSOLE_NAME;
            runCmd.StartInfo.UseShellExecute = true;
            runCmd.StartInfo.RedirectStandardOutput = false;
            runCmd.StartInfo.Arguments = tests.Value.ToString();
    
            if (cbShowConsole.Checked)
            {
                runCmd.StartInfo.CreateNoWindow = true;
                runCmd.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
            }
            else
            {
                runCmd.StartInfo.CreateNoWindow = false;
                runCmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 
            }
            runCmd.Start();                
        }
        catch (Exception ex)
        {
            string t1 = ex.Message;
        }
    }
    

    Note this is intended either to run hidden (CreateNoWindow) or visible.

提交回复
热议问题