| | |
can C# perform command prompt lines
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2007
Posts: 84
Reputation:
Solved Threads: 0
Hi there,
Can C# code , execute commands we write in the cmd window ?
i.e: is there a way to let a C# application interact in somehow the command prompt?
example : we use the command prompt line: ipconfig to see info about the IP address of the machine, can I execute this command from the C#? (I now that there is a way in C# to get the IP address but this is not what I want , the ip address is just an example)
Thanks in advance
Can C# code , execute commands we write in the cmd window ?
i.e: is there a way to let a C# application interact in somehow the command prompt?
example : we use the command prompt line: ipconfig to see info about the IP address of the machine, can I execute this command from the C#? (I now that there is a way in C# to get the IP address but this is not what I want , the ip address is just an example)
Thanks in advance
there's always something to learn
•
•
Join Date: Nov 2006
Posts: 436
Reputation:
Solved Threads: 72
Here is an example. You can also tack on a p.WaitForExit(); if needed.
// Jerry
if this solves your issue, please remember to mark it as solved.
C# Syntax (Toggle Plain Text)
using System.Diagnostics; . . . Process p = new Process(); p.StartInfo.FileName = "IPCONFIG"; p.StartInfo.UseShellExecute = false; p.StartInfo.Arguments = "/all"; p.StartInfo.RedirectStandardOutput = true; p.Start(); textBox1.Text = p.StandardOutput.ReadToEnd();
// Jerry
if this solves your issue, please remember to mark it as solved.
•
•
Join Date: Nov 2007
Posts: 84
Reputation:
Solved Threads: 0
•
•
•
•
Here is an example. You can also tack on a p.WaitForExit(); if needed.
C# Syntax (Toggle Plain Text)
using System.Diagnostics; . . . Process p = new Process(); p.StartInfo.FileName = "IPCONFIG"; p.StartInfo.UseShellExecute = false; p.StartInfo.Arguments = "/all"; p.StartInfo.RedirectStandardOutput = true; p.Start(); textBox1.Text = p.StandardOutput.ReadToEnd();
Thanks
there's always something to learn
•
•
Join Date: Nov 2006
Posts: 436
Reputation:
Solved Threads: 72
DOS commands occur in "that" process. So, the cmdshell does accept the and act upon the CD directive, however, once that command shell closes, the process of changing directories has nothing to do with the next command shell directive because it would be in a new shell.
Maybe what you are looking for can be found at this URL
http://www.codeproject.com/KB/miscct...andprompt.aspx
Maybe what you are looking for can be found at this URL
http://www.codeproject.com/KB/miscct...andprompt.aspx
•
•
Join Date: Jan 2009
Posts: 1
Reputation:
Solved Threads: 1
using System.Diagnostics;
.
.
.
Process p = new Process();
p.StartInfo.FileName = "IPCONFIG";
p.StartInfo.UseShellExecute = false;
p.StartInfo.Arguments = "/all";
p.StartInfo.RedirectStandardOutput = true;
p.Start();
textBox1.Text = p.StandardOutput.ReadToEnd();
This code Works Fantastically fulfilling my present need...
Thank u Jerry
.
.
.
Process p = new Process();
p.StartInfo.FileName = "IPCONFIG";
p.StartInfo.UseShellExecute = false;
p.StartInfo.Arguments = "/all";
p.StartInfo.RedirectStandardOutput = true;
p.Start();
textBox1.Text = p.StandardOutput.ReadToEnd();
This code Works Fantastically fulfilling my present need...
Thank u Jerry
![]() |
Other Threads in the C# Forum
- Previous Thread: Activate form2 when form1 activates(Back to front)
- Next Thread: Learning C-Sharp
| Thread Tools | Search this Thread |
.net access algorithm angle array barchart bitmap box broadcast c# capturing check checkbox client combobox control conversion convert csharp custom database datagrid datagridview dataset datetime dbconnection degrees delegate design development disappear draganddrop drawing encryption enum event excel file firefox form format forms function gdi+ httpwebrequest image index input install java label leak libraries list listbox mandelbrot math monodevelop mouseclick msword mysql operator path pause photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox round server sleep socket sql statistics stream string table tcpclientchannel text textbox thread time timer update usercontrol validation virtualization visualbasic visualstudio webbrowser windows winforms wpf xml






