I
I
Ingvar Von Bjork2016-10-02 12:40:08
Command line
Ingvar Von Bjork, 2016-10-02 12:40:08

How it is possible to catch the text in the console?

There is a program that launches the console and executes certain commands in it. It is required that the result of these commands is transferred to the program itself.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MrDywar Pichugin, 2016-10-02
@Dywar

Something old was

System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.CreateNoWindow = true;
            //p.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8;
            int lcid = GetSystemDefaultLCID();
            var ci = System.Globalization.CultureInfo.GetCultureInfo(lcid);
            var page = ci.TextInfo.OEMCodePage;
            p.StartInfo.StandardOutputEncoding = Encoding.GetEncoding(page);
            p.Start();
            try
            {
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();
                p.StandardInput.AutoFlush = true;
                p.OutputDataReceived += (s, e) => { ... }
                p.ErrorDataReceived += (s, er) =>  { ... }
                while (true)
                { // "\x3" - Ctrl+C
                    if (p.HasExited == true) { break; }
                    p.StandardInput.WriteLine( ... );
                }
            }
            catch (Exception)
            {
                ...
            }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question