473,666 Members | 2,357 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;
ProcessStartInf o psI = new ProcessStartInf o("cmd");

psI.UseShellExe cute = false;
psI.RedirectSta ndardInput = true;
psI.RedirectSta ndardOutput = true;
psI.RedirectSta ndardError = true;
psI.CreateNoWin dow = true;
psI.CreateNoWin dow = false;

p.StartInfo = psI;
p.Start();

sw = p.StandardInput ;
sr = p.StandardOutpu t;
err = p.StandardError ;

sw.AutoFlush = true;

sw.WriteLine("d :");
sw.WriteLine("d ir");

//sw.WriteLine("s sh -2 username@server \"");
//sw.WriteLine("s ecretpassword") ;
sw.Flush();

sw.Close();

MessageBox.Show ("StandardOutpu t - " + sr.ReadToEnd()) ;
MessageBox.Show ("StandardEr ror - " + err.ReadToEnd() );
}
==== END SNIP ====
May 18 '07 #1
0 835

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

Similar topics

2
11072
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 the results are the same on SunOS 5.8, Redhat8.0, cygwin. I read relevant articles and find the reason is that the output of the process exceeds the buffer allocated for that process. So can I adjust the buffer size (on any
1
2596
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
5432
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. Happy New Year -- Gerry
1
1546
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 processing, for instance osql.exe when processing a large job, it doesn't seem that any of the read methods on StandardOutput are able to get the output before the process has exited Is this normal behaviour, and how can I get around it to put the...
13
2694
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, and also from a file conatining the commands 2- does the redirection of the input and output from and to files. 3- retrieve the environment variables like HOME,..
1
1720
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 (derived from System.Web.UI.Page). So, for instance, my home page's inheritance chain looks like this: HomePage Inherits WebPageBase
0
1043
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 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...
1
3764
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 capture the results of the compile and display them in a RichTextBox. The problem I'm having is that when I intentionally introduce an error in the C code I'm compiling, I can't read the error output in my C# program. I've tried redirecting both...
3
1276
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 the uploaded files by the user. My question Is : When you go to web site you find link that allow you to download that file and when you click that link the poup up window show that direct and ask you
0
8440
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8863
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8780
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8636
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7378
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6189
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
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 we have to send another system
2
1763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.