@@ -146,6 +146,12 @@ type purpose =
146
146
| Internal_job
147
147
| Build_job of Path.Build.Set .t
148
148
149
+ let io_to_redirection_path (kind : Io.kind ) =
150
+ match kind with
151
+ | Terminal -> None
152
+ | Null -> Some (Lazy. force Io. null_path)
153
+ | File fn -> Some (Path. to_string fn)
154
+
149
155
let command_line_enclosers ~dir ~(stdout_to : Io.output Io.t )
150
156
~(stderr_to : Io.output Io.t ) ~(stdin_from : Io.input Io.t ) =
151
157
let quote fn = String. quote_for_shell (Path. to_string fn) in
@@ -156,26 +162,26 @@ let command_line_enclosers ~dir ~(stdout_to : Io.output Io.t)
156
162
in
157
163
let suffix =
158
164
match stdin_from.kind with
159
- | Null -> suffix
160
- | Terminal -> suffix
165
+ | Null
166
+ | Terminal ->
167
+ suffix
161
168
| File fn -> suffix ^ " < " ^ quote fn
162
169
in
163
170
let suffix =
164
- match (stdout_to.kind, stderr_to.kind) with
165
- | File fn1 , File fn2 when Path. equal fn1 fn2 -> " &> " ^ quote fn1
166
- | _ -> (
167
- let suffix =
168
- match stdout_to.kind with
169
- | Terminal -> suffix
170
- | Null ->
171
- suffix ^ " > " ^ String. quote_for_shell (Lazy. force Io. null_path)
172
- | File fn -> suffix ^ " > " ^ quote fn
171
+ match
172
+ ( io_to_redirection_path stdout_to.kind
173
+ , io_to_redirection_path stderr_to.kind )
174
+ with
175
+ | Some fn1 , Some fn2 when String. equal fn1 fn2 ->
176
+ " &> " ^ String. quote_for_shell fn1
177
+ | path_out , path_err ->
178
+ let add_to_suffix suffix path redirect =
179
+ match path with
180
+ | None -> suffix
181
+ | Some path -> suffix ^ redirect ^ String. quote_for_shell path
173
182
in
174
- match stderr_to.kind with
175
- | Terminal -> suffix
176
- | Null ->
177
- suffix ^ " 2> " ^ String. quote_for_shell (Lazy. force Io. null_path)
178
- | File fn -> suffix ^ " 2> " ^ quote fn )
183
+ let suffix = add_to_suffix suffix path_out " > " in
184
+ add_to_suffix suffix path_err " 2> "
179
185
in
180
186
(prefix, suffix)
181
187
0 commit comments