473,414 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Process redirection

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 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 1034

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

Similar topics

2
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
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
5
by: Joseph | last post by:
Hello, I have a C# program that builds a txt file and then, calls an external exe (this external exe simply imports this txt file into a DBF (DBase) file. (we copy a template of the DBF file into...
52
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. ...
2
by: Jacek | last post by:
Hello! My application has to use external native library writing to stdout and stdin. My goal is to redirect output within running process (no chance to do that in child process - Process class...
4
by: Marc Jennings | last post by:
Hi all, I want to run an external app from an assembly. Simple enough... > Process ExtProcess = new Process(); > ExtProcess.StartInfo.FileName = myAppName; > ExtProcess.StartInfo.Arguments =...
2
by: Jona | last post by:
Hi, In aspx, the page is reloaded after an event call(i.e button click) has been finished. I need to show up a process indicator image on client's page while executing a server side request...
13
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
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...
12
by: Kevin Walzer | last post by:
I'm trying to learn C. I have a fairly extensive background with C-based scripting languages (Python,Tcl, others), so a great deal of C is proving easy to pick up (control structures, functions,...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.