I am opening the command prompt from c#
Process.Start("cmd");
when it opens i need to write ipconfig automatically such that process opens and finds the ip of the workstation, How should i do that?
I am opening the command prompt from c#
Process.Start("cmd");
when it opens i need to write ipconfig automatically such that process opens and finds the ip of the workstation, How should i do that?
EDIT
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "ipconfig.exe";
p.Start();
p.WaitForExit();
string output = p.StandardOutput.ReadToEnd();
return output;
or
EDIT
Process pr = new Process();
pr.StartInfo.FileName = "cmd.exe";
pr.StartInfo.Arguments = "/k ipconfig";
pr.Start();
Check : How to Execute a Command in C# ?
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "ipconfig";
process.StartInfo = startInfo;
process.Start();
or
Try this
string strCmdText;
strCmdText= "ipconfig";
System.Diagnostics.Process.Start("CMD.exe",strCmdText);
Use this
System.Diagnostics.Process.Start("cmd", "/K ipconfig");
This /K
parameter will start cmd with an ipconfig
command and will show it's output on the console too.
To know more parameters which could be passed to a cmd Go here
there are specific ways to redirect standard input, standard output and error messages when running an external process like in your case, for example check here: ProcessStartInfo.RedirectStandardInput Property
then plenty of examples also here on SO: Sending input/getting output from a console application (C#/WinForms)