I am attempting to use StandardInput.WriteLine (System.Diagnostics NameSpace) to send commands to a chess engine exe. It works great except that for some reason some gibberish (nonsense) characters are send with the actual commands which shouldn’t be there. I tested the code in Visual Studio and it works just fine but when running it with Unity the input string seems to obtain some extra baggage. I thought it might be a problem with the chess engine but it does the same when sending strings to the standard windows console and like I said, the code works flawlessly in Visual Studio. The weird characters look like this ∩╗┐.
Any ideas?
Edit - I stumbled upon a workaround. If I use BaseStream.Write instead, send “\n” afterwords and then do StandardInput.Write(KeyCode.Return) it actually works. No gibberish! It’s not pretty but it works for now. I’d still like to find the root of the problem though. It looks like whenever StandardInput tries to send it’s own newline string something gets mangled.
Sounds like an encoding issue. I would like to know the results of writing your string with StandardInput.Write(stringHere) and then StandardInput.Write(Environment.NewLine) immediately after.
If I try do do the same using StandardInput.Write instead I again get the same bad result. StandardOutput was not redirected so I could see what ends up getting send because I wasn’t getting the expected response to the “uci” command. Like I said, it’s odd that the problem only seems to occur in Unity (MonoDevelop) as I have no problems when using the StandardInput.Write command in Visual Studio.
That’s quite odd… I decided to do a little more research on the problem but came up empty. However, the MSDN suggests using a StreamWriter for redirecting the StandardInput stream.
StreamWriter s = process.StandardInput;
s.WriteLine("line");