.net - Process.kill does not seem to work -


the following code hangs in call waitforexit @ end. terminates cleanly if remove 1 second long sleep. please tell me process die shortly after call kill() on it? many thanks.

    let processstartinfo = system.diagnostics.processstartinfo("c:/cygwin/bin/bash.exe", "-c yes")     processstartinfo.createnowindow <- true     processstartinfo.useshellexecute <- false     processstartinfo.redirectstandardoutput <- true     processstartinfo.redirectstandardinput <- false     processstartinfo.redirectstandarderror <- true                     use proc = new system.diagnostics.process ()                             proc.startinfo <- processstartinfo      let f _ = ()     proc.outputdatareceived.add f     proc.errordatareceived.add f               if not (proc.start())          failwithf "could not start"      proc.beginerrorreadline ()     proc.beginoutputreadline ()      // process terminates fine without     system.threading.thread.sleep (1000)       printf "waiting die"      proc.kill ()              // not seem work     proc.canceloutputread ()     proc.cancelerrorread ()     proc.waitforexit()        // execution gets stuck here, apparently forever 

i don't know f#, code has few strange things; process.read() blocking call, either have make them asynchronous or call .readtoend() instead if want wait until thing redirected finishes. use proc.dispose() or put in using block in c# instead of calling proc.kill(), should done after waitforexit().

check out answer opening dos console.

also check out this reply saying if redirect both stdout , stderr, must make @ least 1 asynchronous.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -