[Mono-bugs] [Bug 80838][Nor] New - Process.StandardOutput not always using the correct encoding
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Tue Feb 13 15:30:42 EST 2007
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by lluis at ximian.com.
http://bugzilla.ximian.com/show_bug.cgi?id=80838
--- shadow/80838 2007-02-13 15:30:42.000000000 -0500
+++ shadow/80838.tmp.28137 2007-02-13 15:30:42.000000000 -0500
@@ -0,0 +1,79 @@
+Bug#: 80838
+Product: Mono: Class Libraries
+Version: 1.2
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs at ximian.com
+ReportedBy: lluis at ximian.com
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Process.StandardOutput not always using the correct encoding
+
+If you start a process using System.Diagnostics.Process, the StandardOutput
+stream is always using utf-8 encoding. The correct behavior would be to use
+the default encoding, since that's the encoding that the process will use
+to write the output.
+
+Here is a test case:
+
+using System;
+using System.Diagnostics;
+
+namespace Xec
+{
+ class MainClass
+ {
+ public static void Main(string[] args)
+ {
+ Console.WriteLine ("se napil luté vody");
+ if (args.Length > 0) {
+ return;
+ }
+
+ Console.WriteLine ("Default Encoding: " +
+System.Text.Encoding.Default.BodyName);
+
+ ProcessStartInfo pinfo = new ProcessStartInfo ("mono", "Main.exe test");
+ pinfo.UseShellExecute = false;
+ pinfo.RedirectStandardOutput = true;
+
+ Process p = Process.Start (pinfo);
+ Console.WriteLine ("Output stream encoding: " +
+p.StandardOutput.CurrentEncoding.BodyName);
+ Console.WriteLine ("Output from process: " + p.StandardOutput.ReadToEnd ());
+ }
+ }
+}
+
+Running this app in a system which has utf-8 as default encoding prints the
+following output:
+
+lluis at portador:~/test> mono Main.exe
+se napil luté vody
+Default Encoding: utf-8
+Output Stream Encoding: utf-8
+Output: se napil luté vody
+
+The first two lines are the output of the app. The other two lines show the
+encoding of the OutputStream and the output read from the other process.
+Everything is correct.
+
+Now, change the terminal encoding to ISO-8859-2, and run the app like this:
+
+lluis at portador:~/test> LANG=cs_CZ.latin2 mono Main.exe
+se napil luté vody
+Default Encoding: iso-8859-2
+Output stream encoding: utf-8
+Output from process: se napil lut vody
+
+The first line is correctly printed, because System.Console will convert
+the output to latin2, but the output from the process is not correct,
+because the OutputStream of the process is using utf-8 to decode the
+output, which is actually latin2.
More information about the mono-bugs
mailing list