1

My application creates a set of sub processes that runs in the background. These processes all have logging both to file and to console. Is it posssible to open up cmd and see the console output of a process after it has been created outside of cmd?

    var p = new Process
            {
                StartInfo =
                {
                    FileName = path,
                    Arguments = arguments,
                    WindowStyle = ProcessWindowStyle.Hidden
                }
            };

    p.Start();
Q-bertsuit
  • 3,223
  • 6
  • 30
  • 55

1 Answers1

1

You can't access the console of the sub-process, but you can redirect the output (stdout and stderr, ideally), and pipe them to your own console/display. An example of redirecting stdout of a sub-process is shown in full on MSDN

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • Yes, that's exactly what I want. To redirect stdout to my own console. Thanks! – Q-bertsuit Jun 24 '20 at 08:39
  • So if I create a process with RedirectStandardOutput = true, is it possible to open cmd and listen in on the ouput? – Q-bertsuit Jun 24 '20 at 08:47
  • @Q-bertsuit I'm not sure what the "open cmd" bit means in there; if you're creating a process, cmd isn't involved at all - it is just your process and the other process, but yes: you can access the three pipes (`stdout`/`stdin`/`stderr`) - but you need to use `UseShellExecute = false` to do this (which is *how/why* you're talking directly to the other process) – Marc Gravell Jun 24 '20 at 09:03
  • I mean if I open the command prompt on Windows,assuming i know the PID, is there any way to "listen" to a stdout that is being redirected from a running process? – Q-bertsuit Jun 24 '20 at 10:33
  • @Q-bertsuit that's a very different question to talking about a process you spawned; "don't know" – Marc Gravell Jun 24 '20 at 16:01
  • Ok, that last question was just out of curiosity. Thanks again! – Q-bertsuit Jun 24 '20 at 19:54