Click here to Skip to main content
15,898,728 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am trying to create a Windows Forms C# project that interacts with the command prompt shell (cmd.exe).
I want to open a command prompt, send a command (like ipconfig) and then read the results back into the windows form ,and can download the related file of the results.
I am stuck. help.....
Posted
Comments
berrymaria 16-Jul-13 22:15pm    
What exactly command you'll gonna use?

Here is the problem: ipconfig is not a "command", this is a regular application. So, "CMD.EXE" is totally redundant and should not be used.

The same goes for data files with file types registered for use with certain application, so the shell API knows about them. In all such cases, you just use System.Diagnostics.Process.Start with the file name and command line parameters. For example:
C#
System.Diagnostics.Process.Start("ipconfig.ехе", "/allcompartments");

The remaining problem is using redirected streams StandardOutput and, just in case, StandardError. The use of redirection is demonstrated on these MSDN pages:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standarderror.aspx[^].

See also:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[^],
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx[^].

—SA
 
Share this answer
 
v2
Please see this link:

C# - Using the Command Prompt[^]
 
Share this answer
 
Comments
WangLirnRen 17-Jul-13 3:27am    
hi,cannot link.help...
berrymaria 17-Jul-13 3:29am    
cannot link in what?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900