Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question