471,089 Members | 1,247 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

C# Process/redirection question

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 ====
May 18 '07 #1
0 770

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by uwnewsgroup | last post: by
1 post views Thread by Peter Åstrand | last post: by
52 posts views Thread by Gerard M Foley | last post: by
1 post views Thread by Jean Harris | last post: by
13 posts views Thread by souissipro | last post: by
reply views Thread by janneman | last post: by
1 post views Thread by =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post: by
3 posts views Thread by =?Utf-8?B?SHVzYW0=?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.