.net - Can't detect exit of cmd command from c# correctly? -


i execute cmd command code, works fine on of commands ver, cd ... on commands netstat or dir on folder many files, need more time execute, cannot detect command finished.

i can use timeout want know why can't detect end of netstat command

string results=""; string command = @"dir c:\windows"; processstartinfo procstartinfo = new processstartinfo("cmd", "/c " + command); procstartinfo.redirectstandardinput = true; procstartinfo.redirectstandardoutput = true; procstartinfo.redirectstandarderror = true; procstartinfo.useshellexecute = false; procstartinfo.createnowindow = true; process proc = new process(); proc.startinfo = procstartinfo; proc.start(); proc.waitforexit();  results = proc.standardoutput.readtoend();  console.writeline(results); 

with code couldn't reproduce problem:

enter image description here

what you're saying isn't possible, using process.waitforexit():

instructs process component wait indefinitely associated process exit.


edit 1:

even using dir c:\windows (which took on minute) unable reproduce problem.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -