Skip to content

Commit

Permalink
add a delay to prevent object disposed exceptions from process on mac…
Browse files Browse the repository at this point in the history
… osx
  • Loading branch information
Albert-Jan Nijburg committed Nov 22, 2016
1 parent eaf899a commit 8e10a94
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions src/app/FakeLib/ProcessHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -434,22 +434,29 @@ let asyncShellExec (args : ExecParams) =
let info =
ProcessStartInfo
(args.Program, UseShellExecute = false,
RedirectStandardError = true, RedirectStandardOutput = true, RedirectStandardInput = true,
WindowStyle = ProcessWindowStyle.Hidden, WorkingDirectory = args.WorkingDirectory,
Arguments = commandLine)
use proc = new Process(StartInfo = info)
proc.ErrorDataReceived.Add(fun e ->
if e.Data <> null then traceError e.Data)
proc.OutputDataReceived.Add(fun e ->
if e.Data <> null then log e.Data)
start proc
proc.BeginOutputReadLine()
proc.BeginErrorReadLine()
proc.StandardInput.Close()
// attaches handler to Exited event, enables raising events, then awaits event
// the event gets triggered even if process has already finished
let! _ = Async.GuardedAwaitObservable proc.Exited (fun _ -> proc.EnableRaisingEvents <- true)
return proc.ExitCode
RedirectStandardError = true, RedirectStandardOutput = true, RedirectStandardInput = true,
WindowStyle = ProcessWindowStyle.Hidden, WorkingDirectory = args.WorkingDirectory,
Arguments = commandLine)
let proc = new Process(StartInfo = info)

try
proc.ErrorDataReceived.Add(fun e ->
if e.Data <> null then traceError e.Data)
proc.OutputDataReceived.Add(fun e ->
if e.Data <> null then log e.Data)
start proc
proc.BeginOutputReadLine()
proc.BeginErrorReadLine()
proc.StandardInput.Close()
// attaches handler to Exited event, enables raising events, then awaits event
// the event gets triggered even if process has already finished
let! _ = Async.GuardedAwaitObservable proc.Exited (fun _ -> proc.EnableRaisingEvents <- true)
return proc.ExitCode
finally
// add a delay because we were seeing ObjectDisposedException when running shell commands on
// osx. Github issue #1424.
Async.Sleep (10) |> Async.RunSynchronously
proc.Dispose()
}

/// Kills the given process
Expand Down

0 comments on commit 8e10a94

Please sign in to comment.