Hi list,
Today and yesterday I am struggling with executing an external program under my C# program. If anybody could give a hand with this, it is greatly appreciated, since it seems that I cannot figure this out myself.
What is the problem ? I am trying to execute the ssh binary to make a connection with my server, see the code snip below. If this code is executed (with the ssh commented out) it gives me back the directory listing as it is supposed to be. In this case everything works well.
But when the ssh command is added, the program stalls. The reason for this is that ssh is waiting for a password. This is clearly visible when the CreateNoWindow is set to true. Apparently sw.WriteLine for sending the secretpassword is not executed. I have the strong feeling that it is waiting for a newline or something silly like that.
Anybody any ideas how to solve this ? Or maybe there exists other ways of accomplishing the same thing ?
Thanks in advance.
Warm regards,
Jan
===== BEGIN SNIP ====
private void btnStart_Click(object sender, EventArgs e)
{
Process p = new Process();
StreamWriter sw;
StreamReader sr;
StreamReader err;
ProcessStartInfo psI = new ProcessStartInfo("cmd");
psI.UseShellExecute = false;
psI.RedirectStandardInput = true;
psI.RedirectStandardOutput = true;
psI.RedirectStandardError = true;
psI.CreateNoWindow = true;
psI.CreateNoWindow = false;
p.StartInfo = psI;
p.Start();
sw = p.StandardInput;
sr = p.StandardOutput;
err = p.StandardError;
sw.AutoFlush = true;
sw.WriteLine("d:");
sw.WriteLine("dir");
//sw.WriteLine("ssh -2 username@server\"");
//sw.WriteLine("secretpassword");
sw.Flush();
sw.Close();
MessageBox.Show("StandardOutput - " + sr.ReadToEnd());
MessageBox.Show("StandardError - " + err.ReadToEnd());
}
==== END SNIP ====