dimanche 28 janvier 2018

How to Attach System.Console class to a running Process?

I'm trying to use external command line app in my application. Here is my code

        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.UseShellExecute = false;
        startInfo.FileName = @"../../console.exe";
        startInfo.WindowStyle = ProcessWindowStyle.Hidden;


        try
        {
            using (Process exeProcess = Process.Start(startInfo))
            {


                var title = Console.Title;
                exeProcess.WaitForExit();
            }
        }
        catch (Exception)
        {


        }

But the problem is after the process is started, I can't changing anything with System.Console class.

When I try to Debug on Console.Title line, Visual Studio telling me Console.Title is null.

I tried to "Attach to Process" in Debug Menu in Visual Studio and it worked but I just want to do it with code.

So how can I attach System.Console class to "exeProcess" ?

Edit: My running exe file's PID is 8086 and exeProcess's Id is 7248. Its loading external console app in my application but still have different PID's. How can i make them same PID?





Aucun commentaire:

Enregistrer un commentaire