Home > Net >  C # CMD command continuous input and feedback
C # CMD command continuous input and feedback

Time:01-15

Checked online, has written the following code, serial input and see feedback
CmdProcess=new Process ();//create the process object
CmdProcess. StartInfo. FileName="CMD. Exe";//set to execute commands

CmdProcess. StartInfo. UseShellExecute=false;//whether or not to use the operating system shell startup
CmdProcess. StartInfo. RedirectStandardInput=true;//to accept input from the caller information
CmdProcess. StartInfo. RedirectStandardOutput=true;//by calling program output information
CmdProcess. StartInfo. RedirectStandardError=true;//to redirect the standard error output
CmdProcess. StartInfo. CreateNoWindow=true;///false application Windows not being displayed is to create the window


CmdProcess. Start ();
CmdProcess. StandardInput. WriteLine (" ipconfig& The exit ");//+ "& amp; The exit "
TextBoxCMDShow. Text=CmdProcess. StandardOutput. ReadToEnd () + TextBoxCMDShow. The Text;
CmdProcess. StandardInput. WriteLine (" the route print& The exit ");
TextBoxCMDShow. Text=CmdProcess. StandardOutput. ReadToEnd () + TextBoxCMDShow. The Text;
CmdProcess. StandardInput. WriteLine (" exit ");

Found that only the first ipconfig output, the second route print is empty,
I suspect the & amp; The exit, but without the exit, to StandardOutput. Readtoend is stuck, perform not bottom go to,
If there is a great god to reassure?

  •  Tags:  
  • C#
  • Related