简体   繁体   English

产生不同输出的控制台子进程

[英]spawning console sub process with different output

I have a console application written in c# which starts a new process. 我有一个用c#编写的控制台应用程序,它开始了一个新过程。 This new process is also a console application. 这个新过程也是一个控制台应用程序。 The problem is that whole child process output goes to parent console window and i don't want it to. 问题是整个子进程的输出都转到父控制台窗口,而我不希望这样做。 It doesn't matter if it creates a new console window or not, I don't need it. 它是否创建一个新的控制台窗口都没有关系,我不需要它。

Edit: 编辑:

Process p = new Process(); 
p.StartInfo.FileName = @"C:\example.exe";
p.Start();

I tried some additional setting like CreateNoWindow, RedirectOutput and so on but with no luck 我尝试了一些其他设置,例如CreateNoWindow,RedirectOutput等,但是没有运气

Normally, when you create a child process, a new console window pops up and all output of the child process ends up in that window. 通常,当您创建子进程时,会弹出一个新的控制台窗口,并且该子进程的所有输出都将在该窗口中结束。 Here is a sample program that exhibits this behavior: 这是表现出此行为的示例程序:

using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;

static class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("TEST");

        if (args.Length == 0)
        {
            string path = Assembly.GetExecutingAssembly().Location;
            Process.Start(path, "DontStartProcess");
        }
        Console.ReadLine();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM