473,506 Members | 16,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Process/redirection question

8 New Member
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 828

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

Similar topics

2
11062
by: uwnewsgroup | last post by:
When I was using Runtime.exec(String cmd) to run a unix utility (join), and try to get its standard output by using Process.getOutputStream(), it blocks forever. I tried it using Java 1.4 and...
1
2584
by: Peter Åstrand | last post by:
There's a new PEP available: PEP 324: popen5 - New POSIX process module A copy is included below. Comments are appreciated. ---- PEP: 324 Title: popen5 - New POSIX process module
52
5389
by: Gerard M Foley | last post by:
Can one write a webpage which is not displayed but which simply redirects the user to another page without any action by the user? Sorry if this is simple, but I am sometimes simple myself. ...
1
1537
by: Jean Harris | last post by:
If I redirect the console output using the standard method, it works fine if the process outputs all its information and then exits quite soon. But for processes that output information as they are...
13
2679
by: souissipro | last post by:
Hi, I have written a C program that does some of the functionalities mentionned in my previous topic posted some days ago. This shell should: 1- execute input commands from standard input,...
1
1715
by: Mike Hofer | last post by:
I really need some help, and I'd appreciate any that you folks can provide. The ASP.NET application in question uses version 1.1 of the .NET Framework. All of the pages use a common base class...
0
1038
by: janneman | last post by:
Hi list, At first I posted this question in the .Net group, but later I thought that this group could me more appropriate...... Today and yesterday I am struggling with executing an external...
1
3757
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I have a C# application in which I start another process which produces output to stdout and stderr. In fact, that process is the uSoft VS2005 C/C++ compiler itself! I would like to...
3
1265
by: =?Utf-8?B?SHVzYW0=?= | last post by:
Hi EveryBody: I am working in ASP.Net 2.0 by Vb.Net the code behaind, My project Is a web site that allow the user to upload and download file to the web site. I have database that will save all...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.