I have this block of code, which I'm using to enter a command and retrieve the result:
It works, except that the application locks when I reach the line highlighted on the code. On debug the yellow arrow simply disappear when reaches the while loop for the last time (end of stream).Code:private void Cmd(string command, string parameter, object stream) { StreamWriter writer = (StreamWriter)stream; StreamWriter input; StreamReader output; Process process = new Process(); try { process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardInput = true; process.StartInfo.FileName = "cmd"; process.Start(); input = process.StandardInput; output = process.StandardOutput; input.WriteLine("help"); while(!output.EndOfStream) //Locks when reach end of stream { writer.WriteLine(output.ReadLine()); Debug.WriteLine(output.ReadLine()); } } catch (Exception e) { InsertLog(2, "Could not run CMD command"); writer.WriteLine("Not valid. Ex: " + e.Message); } writer.Flush(); }


Reply With Quote

Bookmarks