Process output redirection on a single console line

后端 未结 2 1862
再見小時候
再見小時候 2021-01-14 09:47

I am writing a C# application that can launch third party command line executables and redirect their standard output to a RichTextBox.

I am able to redirect the out

2条回答
  •  难免孤独
    2021-01-14 10:32

    This code will fix up raw output and make it as it would appear on the terminal.

     //Deletes all lines that end with only a CR - this emulates the output as it would be seen cmd
    public static string DeleteCRLines( this string Str) {
        Str = Str.Replace( "\r\r\n", "\r\n");
        //Splits at the CRLF. We will end up with 'lines' that are full of CR - the last CR-seperated-line is the one we keep
        var AllLines = new List( Str.Split( new[] {"\r\n"}, StringSplitOptions.None));
        for (int i = 0; i < AllLines.Count; i++){
            var CRLines = AllLines[i].Split('\r');
            AllLines[i] = CRLines[ CRLines.Count() -1];
        }
        return String.Join( Environment.NewLine, AllLines.ToArray());
    }
    

提交回复
热议问题