.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:
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
Post a Comment