Basically I create a command line GUI. The user sees the command line output in the extended text field and enters the commands in the form of a simple text field below it. I managed to do this work, EXCEPT that it seems to me impossible to get color information. For example, if I run a program that displays red error text, I do not get the bytes of the color code, they simply are not in the stream!
Here is what I am doing now. To start the process:
ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\Windows\System32\cmd.exe"); startInfo.UseShellExecute = false; startInfo.CreateNoWindow = true; startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardInput = true; startInfo.RedirectStandardError = true; this.promptProcess = Process.Start(startInfo);
Then I create a stream that reads from the output stream and sends it to the text box:
while (true) { while (this.stream.EndOfStream) ; //read until there nothing left in the stream, writing to the (locked) output box byte [] buffer = new byte[1000]; int numberRead; StringBuilder builder = new StringBuilder(); do { numberRead = this.stream.BaseStream.Read(buffer, 0, buffer.Length); char[] characters = UTF8Decoder.GetChars(buffer, 0, numberRead); builder.Append(characters); } while (numberRead == buffer.Length); this.writeToOutput(builder.ToString()); }
Even if I use my prompt to launch an application that displays colored text, I do not receive any additional color information (even ANSI color codes do not mix with text). As you can see above, I go to BaseStream and read the bytes and then decrypt them in UTF8. Unfortunately, it seems that even raw bytes do not include the original color information.
How can I get the source stream from the applications that I run without any filtering? I want raw bytes so that I can do my own color analysis and display console color output.
To clarify, I am not asking how to interpret color codes. I just want to make them available in the stream.
source share