I have a console app and a win forms app that both need to call out to a remote server for some data, they make a call to the command line part of Putty, plink.exe, to run a remote command over SSH.
I created a tiny class library for both to share, running the following:
public static string RunCommand(string command, string arguments) {
ProcessStartInfo startInfo = new ProcessStartInfo {
FileName = command,
Arguments = arguments,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true
};
string output = null;
using (Process p = new Process()) {
p.StartInfo = processStartInfo;
p.Start();
output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
}
return output;
}
Under the console application everything works fine, under the win forms it doesn't error, it seems that WaitForExit() just doesn't wait. I get an empty string for output. I've confirmed from the remote server the user logged in, so it seems the command has run.
Any ideas?