Hey there,
Deadlocks are a common issue when working with RedirectStandardInput & Output. The way to avoid this is to close the RedirectIO. In your example you already flushed it but did not close it.
As for output. Reading line by line is just a waste because ReadToEnd() will also supply the \r\n. And if you want only \n you can do a small:
output = output.Replace("\r\n", "\n");
To avoid deadlocks in your script this should do the trick:
Process nslookup = new Process()
{
StartInfo = new ProcessStartInfo("nslookup")
{
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
}
};
nslookup.Start();
nslookup.StandardInput.WriteLine("set type=srv");
nslookup.StandardInput.WriteLine("_ldap._tcp.domain.local");
nslookup.StandardInput.Flush();
nslookup.StandardInput.Close();
string output = nslookup.StandardOutput.ReadToEnd();
nslookup.WaitForExit();
nslookup.Close();