One of my hobbies is to collect functions shared online.Code. It is very convenient to collect and use it. This section is smallProgramCan be used to directly run the batch processing (CMD) statement or the batch processing file (*. Bat | *. com), and obtain the returned text after the batch processing statement is run. Very good, very powerful. In addition to running cmd, you can also directly run EXE or other programs and set whether to run in silent mode in the future. The main technology used is process.
Protected static void runcmd (string cmd, Boolean showwindow, Boolean waitforexit) {writeline ("runcmd" + cmd); var P = new process (); var Si = new processstartinfo (); vaR Path = environment. systemdirectory; Path = path. combine (path, @ "cmd.exe"); SI. filename = path; If (! Cmd. startswith (@ "/") cmd = @ "/C" + cmd; Si. Arguments = cmd; Si. useshellexecute = false; Si. createnowindow =! Showwindow; SI. redirectstandardoutput = true; SI. redirectstandarderror = true; p. startinfo = SI; p. start (); If (waitforexit) {P. waitforexit (); var STR = P. standardoutput. readtoend (); If (! String. isnullorempty (STR) writeline (Str. trim (New char [] {'\ R',' \ n', '\ t '}). trim (); STR = P. standarderror. readtoend (); If (! String. isnullorempty (STR) writeline (Str. trim (New char [] {'\ R',' \ n', '\ t '}). trim ());}}
This code is from the newlife component. New life Website: http://www.newlifex.com/