I want to delete multiple lines of file's output .which file is redirected
I want to开发者_运维百科 delete multiple string lines of files output.which file is redirected. My code is as follows.
static void Main(string[] args)
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd ";
p.StartInfo.UseShellExecute = false;
p.StartInfo.Arguments = "/C ipconfig";
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Console.WriteLine(output);
Console.ReadLine();
}
OUTPUT : I give correct answer.but i want only ip address of m/c. Other lines are deleted. please give the answer of question with changes of code.
Do you really need to run ipconfig? The NetworkInterface
class should be able to provide you the information you are looking for without requiring you to run an external process and parse text.
static void Main(string[] args) { System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = "cmd "; p.StartInfo.UseShellExecute = false; p.StartInfo.Arguments = "/C net view"; p.StartInfo.RedirectStandardOutput = true; p.Start(); string output = p.StandardOutput.ReadToEnd(); p.WaitForExit(); Console.WriteLine(output); Console.ReadLine(); }
OUTPUT : server name remark
//st1 //st2 //satishlap //st6 //st10 command is completed successfully.
I give correct output.I want to only server name(//st1,//st2,//satishlap,//st6,//st10). other infoemation is deleted. please the answer of my question with the changes of code.
精彩评论