Skip to content

Commit 8e10a94

Browse files
author
Albert-Jan Nijburg
committed
add a delay to prevent object disposed exceptions from process on mac osx
1 parent eaf899a commit 8e10a94

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

src/app/FakeLib/ProcessHelper.fs

+23-16
Original file line numberDiff line numberDiff line change
@@ -434,22 +434,29 @@ let asyncShellExec (args : ExecParams) =
434434
let info =
435435
ProcessStartInfo
436436
(args.Program, UseShellExecute = false,
437-
RedirectStandardError = true, RedirectStandardOutput = true, RedirectStandardInput = true,
438-
WindowStyle = ProcessWindowStyle.Hidden, WorkingDirectory = args.WorkingDirectory,
439-
Arguments = commandLine)
440-
use proc = new Process(StartInfo = info)
441-
proc.ErrorDataReceived.Add(fun e ->
442-
if e.Data <> null then traceError e.Data)
443-
proc.OutputDataReceived.Add(fun e ->
444-
if e.Data <> null then log e.Data)
445-
start proc
446-
proc.BeginOutputReadLine()
447-
proc.BeginErrorReadLine()
448-
proc.StandardInput.Close()
449-
// attaches handler to Exited event, enables raising events, then awaits event
450-
// the event gets triggered even if process has already finished
451-
let! _ = Async.GuardedAwaitObservable proc.Exited (fun _ -> proc.EnableRaisingEvents <- true)
452-
return proc.ExitCode
437+
RedirectStandardError = true, RedirectStandardOutput = true, RedirectStandardInput = true,
438+
WindowStyle = ProcessWindowStyle.Hidden, WorkingDirectory = args.WorkingDirectory,
439+
Arguments = commandLine)
440+
let proc = new Process(StartInfo = info)
441+
442+
try
443+
proc.ErrorDataReceived.Add(fun e ->
444+
if e.Data <> null then traceError e.Data)
445+
proc.OutputDataReceived.Add(fun e ->
446+
if e.Data <> null then log e.Data)
447+
start proc
448+
proc.BeginOutputReadLine()
449+
proc.BeginErrorReadLine()
450+
proc.StandardInput.Close()
451+
// attaches handler to Exited event, enables raising events, then awaits event
452+
// the event gets triggered even if process has already finished
453+
let! _ = Async.GuardedAwaitObservable proc.Exited (fun _ -> proc.EnableRaisingEvents <- true)
454+
return proc.ExitCode
455+
finally
456+
// add a delay because we were seeing ObjectDisposedException when running shell commands on
457+
// osx. Github issue #1424.
458+
Async.Sleep (10) |> Async.RunSynchronously
459+
proc.Dispose()
453460
}
454461

455462
/// Kills the given process

0 commit comments

Comments
 (0)