@@ -65,21 +65,6 @@ module Commands =
6565 // returns exit code, stdio and stderr as string arrays
6666 let executeProcess pathToExe arguments workingDir =
6767 let commandLine = ResizeArray()
68- let errorsList = ResizeArray()
69- let outputList = ResizeArray()
70- let errorslock = obj()
71- let outputlock = obj()
72- let outputDataReceived ( message : string ) =
73- if not ( isNull message) then
74- lock outputlock ( fun () ->
75- printfn " %s " message
76- outputList.Add( message))
77-
78- let errorDataReceived ( message : string ) =
79- if not ( isNull message) then
80- lock errorslock ( fun () ->
81- eprintfn " %s " message
82- errorsList.Add( message))
8368
8469 commandLine.Add $" cd {workingDir}"
8570 commandLine.Add $" {pathToExe} {arguments} /bl"
@@ -103,29 +88,14 @@ module Commands =
10388 use p = new Process()
10489 p.StartInfo <- psi
10590
106- p.OutputDataReceived.Add( fun a -> outputDataReceived a.Data)
107- p.ErrorDataReceived.Add( fun a -> errorDataReceived a.Data)
108-
109- if p.Start() then
110- p.BeginOutputReadLine()
111- p.BeginErrorReadLine()
112- p.WaitForExit()
113-
114- let workingDir ' =
115- if workingDir = " "
116- then
117- // Assign working dir to prevent default to C:\Windows\System32
118- let executionLocation = Assembly.GetExecutingAssembly() .Location
119- Path.GetDirectoryName executionLocation
120- else
121- workingDir
122-
123- lock gate ( fun () ->
124- File.WriteAllLines( Path.Combine( workingDir', " commandline.txt" ), commandLine)
125- File.WriteAllLines( Path.Combine( workingDir', " StandardOutput.txt" ), outputList)
126- File.WriteAllLines( Path.Combine( workingDir', " StandardError.txt" ), errorsList)
127- )
128- p.ExitCode, outputList.ToArray(), errorsList.ToArray()
91+ if not ( p.Start()) then failwith " new process did not start"
92+
93+ let readOutput = backgroundTask { return ! p.StandardOutput.ReadToEndAsync() }
94+ let readErrors = backgroundTask { return ! p.StandardError.ReadToEndAsync() }
95+
96+ p.WaitForExit()
97+
98+ p.ExitCode, readOutput.Result, readErrors.Result
12999
130100 let getfullpath workDir ( path : string ) =
131101 let rooted =
0 commit comments