@@ -11,10 +11,13 @@ let gitlab_repo ~bot_info ~gitlab_domain ~gitlab_full_name =
11
11
|> Result. map ~f: (fun token ->
12
12
f " https://oauth2:%s@%s/%s.git" token gitlab_domain gitlab_full_name )
13
13
14
- let report_status ?(mask = [] ) command report code =
14
+ let report_status ?(mask = [] ) ?(stderr_content = " " ) command report code =
15
+ let stderr =
16
+ if String. is_empty stderr_content then " " else stderr_content ^ " \n "
17
+ in
15
18
Error
16
19
(List. fold_left
17
- ~init: (f {| Command " %s" % s % d% s| } command report code " \n " )
20
+ ~init: (f {| Command " %s" % s % d% s% s | } command report code " \n " stderr )
18
21
~f: (fun acc m -> Str. global_replace (Str. regexp_string m) " XXXXX" acc)
19
22
mask )
20
23
@@ -89,12 +92,18 @@ let ( |&& ) command1 command2 = command1 ^ " && " ^ command2
89
92
let execute_cmd ?(mask = [] ) command =
90
93
Lwt_io. printf " Executing command: %s\n " command
91
94
>> = fun () ->
92
- Lwt_unix. system command
93
- > |= fun status ->
95
+ let process = Lwt_process. open_process_full (Lwt_process. shell command) in
96
+ let stdout_pipe = copy_stream ~src: process#stdout ~dst: Lwt_io. stdout in
97
+ let stderr_pipe = copy_stream ~src: process#stderr ~dst: Lwt_io. stderr in
98
+ (* Capture stdout and stderr in parallel *)
99
+ (* Wait for the process to finish *)
100
+ let + _stdout_content = stdout_pipe
101
+ and + stderr_content = stderr_pipe
102
+ and + status = process#status in
94
103
match status with
95
104
| Unix. WEXITED code ->
96
105
if Int. equal code 0 then Ok ()
97
- else report_status ~mask command " exited with status" code
106
+ else report_status ~mask ~stderr_content command " exited with status" code
98
107
| Unix. WSIGNALED signal ->
99
108
report_status ~mask command " was killed by signal number" signal
100
109
| Unix. WSTOPPED signal ->
0 commit comments