I have a console application and an application for forms of winnings, which must be called to a remote server for some data, they make a call to the Putty command line part, plink.exe, to run the remote command via SSH.
I created a tiny class library for sharing by doing 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; }
In the console application, everything works fine, within the framework of the winning forms, this is not an error, it seems that WaitForExit () just does not wait. I get an empty string for output. I confirmed from the remote server that the user is logged in, so it seems that the command is running.
Any ideas?
Gavin source share