Am running a python script from unity, and I want the output to be displayed in a GUI label in unity, the output contain special characters like é,ç,... but am getting symbols instead. This is what I tried so far but no luck
using (Process proc = Process.Start (start)) { using (StreamReader reader = proc.StandardOutput) { string result = reader.ReadToEnd (); UTF8Encoding utf8 = new UTF8Encoding (); byte[] encodedBytes = utf8.GetBytes (result); UnityEngine.Debug.Log (result); Message1.text = result; } }
result is the output: it should be
('fromaje', 'Fausse:') ('Correction suggérér:','fromage')
But am getting:
1 Answers
Answers 1
When you create your process use:
var proc = new Process { StartInfo = new ProcessStartInfo { FileName = "python.exe whatever.py", Arguments = "yourargs", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true } };
Then read the string by doing this:
proc.Start(); StringBuilder bldr = new StringBuilder(); while (!proc.StandardOutput.EndOfStream) { bldr.append(proc.StandardOutput.ReadLine()+"\n"); }
You can get the full output by doing:
bldr.ToString()
0 comments:
Post a Comment