473,395 Members | 1,931 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,395 software developers and data experts.

Process and Cmd.exe problem


Hello,

I am doing an automatic backup service using c# and VS2003.
To achieve this i must call an executable file. So far I have made
it all work using Process, code looks like this:

Expand|Select|Wrap|Line Numbers
  1. Process cmd = new Process();
  2. StreamWriter sw;
  3. StreamReader sr;
  4. StreamReader err;
  5.  
  6. cmd.StartInfo.RedirectStandardInput = true;
  7. cmd.StartInfo.RedirectStandardOutput = true;
  8. cmd.StartInfo.RedirectStandardError = true;
  9. cmd.StartInfo.CreateNoWindow = true;
  10. cmd.StartInfo.UseShellExecute = false;
  11. cmd.StartInfo.FileName = "cmd.exe";
  12.  
  13. cmd.Start();
  14.  
  15. sw = cmd.StandardInput;
  16. sr = cmd.StandardOutput;
  17. err = cmd.StandardError;
  18.  
  19. sw.AutoFlush = true;
  20. if (textBox1.Text != "")  // textBox1 contains the path+name of .exe
  21. sw.WriteLine(textBox1.Text);
  22.  
  23. sw.Close();
  24.  
  25. richTextBox1.Text = sr.ReadToEnd();
  26. richTextBox1.Text += err.ReadToEnd();
  27.  
Problem is that the executable may in most cases
ask for a password. I have found no way how to check
for this and supply the password. After executing the
above code the Process terminates.

How can I tell the Process to wait if the executable is
waiting for input? Or is there another way to accomplish
this??

Kind Regards,
Robert

Apr 20 '06 #1
1 4062


I still haven't found a solution to my problem, but I am trying another
approach now.

If i set StartInfo.UseShellExecute = true, and StartInfo.FileName = "cmd.exe".
A cmd window will open. How can I from c# send commands to this windows?

If this is possible then my problem should be solved.
Kind Regards,
Robert


"Robert" wrote:

Hello,

I am doing an automatic backup service using c# and VS2003.
To achieve this i must call an executable file. So far I have made
it all work using Process, code looks like this:

Expand|Select|Wrap|Line Numbers
  1.  Process cmd = new Process();
  2.  StreamWriter sw;
  3.  StreamReader sr;
  4.  StreamReader err;
  5.  cmd.StartInfo.RedirectStandardInput = true;
  6.  cmd.StartInfo.RedirectStandardOutput = true;
  7.  cmd.StartInfo.RedirectStandardError = true;
  8.  cmd.StartInfo.CreateNoWindow = true;
  9.  cmd.StartInfo.UseShellExecute = false;
  10.  cmd.StartInfo.FileName = "cmd.exe";
  11.  cmd.Start();
  12.  sw = cmd.StandardInput;
  13.  sr = cmd.StandardOutput;
  14.  err = cmd.StandardError;
  15.  sw.AutoFlush = true;
  16.  if (textBox1.Text != "")  // textBox1 contains the path+name of .exe
  17.      sw.WriteLine(textBox1.Text);
  18.  sw.Close();
  19.  richTextBox1.Text = sr.ReadToEnd();
  20.  richTextBox1.Text += err.ReadToEnd();
  21.  

Problem is that the executable may in most cases
ask for a password. I have found no way how to check
for this and supply the password. After executing the
above code the Process terminates.

How can I tell the Process to wait if the executable is
waiting for input? Or is there another way to accomplish
this??

Kind Regards,
Robert

Apr 21 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Sorin Dolha [MCSD .NET] | last post by:
I would like to start a process from C# code as another user. The C# code is executed as the ASPNET user because it relies in a Web Page class, and I would like that the process will run as another...
2
by: Praveen K | last post by:
I have a problem in communicating between the C# and the Excel Interop objects. The problem is something as described below. I use Microsoft Office-XP PIA dll’s as these dll’s were been...
12
by: Raymond Lewallen | last post by:
How to wait for a process to stop completion is my goal. Obviously, the looping while waiting for the HasExited property is not a solution.. but thats the best I can come up off the top of my...
80
by: Charles Law | last post by:
Hi guys I have a time critical process, running on a worker thread. By "time critical", I mean that certain parts of the process must be completed in a specific time frame. The time when the...
22
by: Zen | last post by:
Hi, My production machine has 2G of memory, when aspnet_wp.exe goes up to about ~1.2G of memory usage, I start get out-of-memory exception. Other processes don't use as much memory and I added...
5
by: Benzi Eilon | last post by:
I have written a C# application which should run as a Windows Service. I must avoid having multiple instances of the application on one machine so I inserted the following code at the beginning of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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...

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.