Capturing output from standard io encoding?

I am collecting application output in my .NET application.

The encoding is somewhat strange. ÅÄÖ letters are displayed as ├Ñ ├├ ├Â

I tried to convert back and forth from different encodings without any success. Does anyone know how a string should be correctly converted here?

eg. the documentation for the application says that the output is UTF8, so I tried this:

byte[] encodedBytes = Encoding.UTF8.GetBytes(theOutput); var res = Encoding.Default.GetString(encodedBytes); 

What causes the wrong result.

edit: code:

 var processStartInfo = new ProcessStartInfo { CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardInput = true, UseShellExecute = false, Arguments = a, FileName = path + "\\phantomjs.exe" }; var process = new Process { StartInfo = processStartInfo, EnableRaisingEvents = true }; //capturing output here process.OutputDataReceived += (sender, args) => outputBuilder.Append(args.Data); process.Start(); process.BeginOutputReadLine(); process.WaitForExit(20000); process.CancelOutputRead(); 
+4
source share
1 answer

Found a solution. You can set

  processStartInfo.StandardOutputEncoding = Encoding.UTF8; 

This concludes correctly.

+10
source

Source: https://habr.com/ru/post/1495539/


All Articles