1 classCommand2 {3 Public Static stringStartcmd (stringcommand)4 {5 stringOutput ="";6 Try7 {8 9Process cmd =NewProcess ();TenCmd. Startinfo.filename =command; One ACmd. Startinfo.useshellexecute =false; - -Cmd. Startinfo.redirectstandardinput =true; theCmd. Startinfo.redirectstandardoutput =true; - -Cmd. Startinfo.createnowindow =true; -Cmd. Startinfo.windowstyle =Processwindowstyle.hidden; + - cmd. Start (); + AOutput =cmd. Standardoutput.readtoend (); at Console.WriteLine (output); - cmd. WaitForExit (); - cmd. Close (); - } - Catch(Exception e) - { in Console.WriteLine (e); - } to returnoutput; + } - Public StaticProcess Startcmd (stringCommandstringargument) the { * stringOutput =""; $Process cmd =NewProcess ();Panax Notoginseng Try - { theCmd. Startinfo.filename =command; +Cmd. Startinfo.arguments =argument; A theCmd. Startinfo.useshellexecute =false; + -Cmd. Startinfo.redirectstandardinput =true; $Cmd. Startinfo.redirectstandardoutput =true; $ -Cmd. Startinfo.createnowindow =true; -Cmd. Startinfo.windowstyle =Processwindowstyle.hidden; the - cmd. Start ();Wuyi the //output = cmd. Standardoutput.readtoend (); - //Console.WriteLine (output); Wu //cmd. WaitForExit (); - //cmd. Close (); About } $ Catch(Exception e) - { - Console.WriteLine (e); - } A returncmd; + } the}
View Code
C # cmd Crane performs a pass-through execution class