Public Static voidRuncmd (stringcmd) {stringCmdpath =@"C:\Windows\System32\cmd.exe"; CMD= cmd. Trim (). TrimEnd ('&') +"&exit"or//To add the Exit command, or later call ReadToEnd () command will be suspended animationusing(Process p =NewProcess ()) {p.StartInfo.FileName=Cmdpath; P.startinfo.useshellexecute=false; P.startinfo.redirectstandardinput=true; P.startinfo.redirectstandardoutput=true; P.startinfo.redirectstandarderror=true; P.startinfo.createnowindow=true; P.start (); P.standardinput.writeline (CMD); P.standardinput.autoflush=true; p.WaitForExit (); P.close (); } }
Call:
stringSidmpath =@"E:\Software\idman_lv\IDM\IDMan.exe"; stringSdownloadpath= "http://pan.baidu.com/s/...";//Net-disk linkstringSoutputpath =@"D:\TempFolder\"; stringSfilename= Guid.NewGuid (). ToString () + ". pdf"; stringScmd =string. Format (@"{0}/d "" {1} ""/P "" {2} ""/F "" {3} """, Sidmpath, Sdownloadpath, Soutputpath, sfilename); Cmdbox.appendtext (Scmd+"\ n"); Sqlprocs.runcmd (scmd);
Note: If there are spaces in the calling program path, the cmd command fails to execute and can be enclosed in double quotation marks.
C # calls cmd and downloads files using IDM