Hallo zusammen,
ich hoffe, dieses Forum ist richtig. Hier erstmal ein Stückchen Code:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33:
| String command; String stdOut; String stdErr; int exitCode;
System.Diagnostics.Process myProcess = new System.Diagnostics.Process(); myProcess.StartInfo.UseShellExecute = false; myProcess.StartInfo.CreateNoWindow = true; myProcess.StartInfo.RedirectStandardOutput = true; myProcess.StartInfo.RedirectStandardError = true; myProcess.StartInfo.FileName = "cmd.exe"; myProcess.StartInfo.Arguments = "/C " + command; myProcess.EnableRaisingEvents = true; try { myProcess.Start(); System.IO.StreamReader sOut = myProcess.StandardOutput; System.IO.StreamReader sErr = myProcess.StandardError; stdOut = sOut.ReadToEnd(); stdErr = sErr.ReadToEnd();
myProcess.WaitForExit(); exitCode = myProcess.ExitCode;
sErr.Close(); sOut.Close(); myProcess.Close(); } catch ... |
Ich lese den Output ein, den mir eine aufgerufene Exe-Datei zurückliefert.
Mein Problem ist, dass die deutschen Umlaute dabei falsch eingelesen werden.
Als Encoding wird automatisch Windows-1252 genommen, und laut
en.wikipedia.org/wiki/Windows-1252 enthält das Encoding auch ä, ö, ü (und ß).
Allerdings wird ä nun zu ", ö zu ", ü zu einem Kästchen und ß zu á beim Auslesen.
Anstatt
C#-Quelltext
1:
| System.IO.StreamReader sOut = myProcess.StandardOutput; |
würde ich gerne so etwas machen wie
C#-Quelltext
1:
| System.IO.StreamReader sOut = new StreamReader(myProcess.StandardOutput, Encoding.XYZ); |
um mal noch andere Encodings durchzuprobieren, was aber leider nicht geht, da myProcess.StandardOutput schon einen StreamReader liefert, der Constructor von StreamReader aber als ersten Parameter z.B. einen Stream erwartet...
Könnt ihr mir sagen, wie ich einem StreamReader ein spezielles Encoding mitgeben kann?
Oder muss das vielleicht erst bei
stdOut = sOut.ReadToEnd(); gemacht werden? Nur wie?
Freue mich auf Antwort
Viele Grüße
PoiSoN