@@ -34,6 +34,7 @@ module Node.ChildProcess
34
34
, SpawnOptions ()
35
35
, defaultSpawnOptions
36
36
, exec
37
+ , execFile
37
38
, ExecOptions ()
38
39
, ExecResult ()
39
40
, defaultExecOptions
@@ -220,8 +221,10 @@ defaultSpawnOptions =
220
221
, gid: Nothing
221
222
}
222
223
223
- -- | Similar to `spawn`, except that this variant will buffer output, and wait
224
- -- | until the process has exited before calling the callback.
224
+ -- | Similar to `spawn`, except that this variant will:
225
+ -- | * run the given command with the shell,
226
+ -- | * buffer output, and wait until the process has exited before calling the
227
+ -- | callback.
225
228
-- |
226
229
-- | Note that the child process will be killed if the amount of output exceeds
227
230
-- | a certain threshold (the default is defined by Node.js).
@@ -231,28 +234,53 @@ exec :: forall eff.
231
234
(ExecResult -> Eff (cp :: CHILD_PROCESS | eff ) Unit ) ->
232
235
Eff (cp :: CHILD_PROCESS | eff ) Unit
233
236
exec cmd opts callback =
234
- execImpl cmd (convert opts) \err stdout' stderr' ->
235
- callback { error: ( toMaybe err)
237
+ execImpl cmd (convertExecOptions opts) \err stdout' stderr' ->
238
+ callback { error: toMaybe err
236
239
, stdout: stdout'
237
240
, stderr: stderr'
238
241
}
239
- where
240
- convert opts =
241
- { cwd: fromMaybe undefined opts.cwd
242
- , env: fromMaybe undefined opts.env
243
- , timeout: fromMaybe undefined opts.timeout
244
- , maxBuffer: fromMaybe undefined opts.maxBuffer
245
- , killSignal: fromMaybe undefined opts.killSignal
246
- , uid: fromMaybe undefined opts.uid
247
- , gid: fromMaybe undefined opts.gid
248
- }
249
242
250
- foreign import execImpl :: forall eff opts .
243
+ foreign import execImpl :: forall eff .
251
244
String ->
252
- { | opts } ->
245
+ ActualExecOptions ->
253
246
(Nullable Exception.Error -> Buffer -> Buffer -> Eff (cp :: CHILD_PROCESS | eff ) Unit ) ->
254
247
Eff (cp :: CHILD_PROCESS | eff ) Unit
255
248
249
+ -- | Like `exec`, except instead of using a shell, it passes the arguments
250
+ -- | directly to the specified command.
251
+ execFile :: forall eff .
252
+ String ->
253
+ Array String ->
254
+ ExecOptions ->
255
+ (ExecResult -> Eff (cp :: CHILD_PROCESS | eff ) Unit ) ->
256
+ Eff (cp :: CHILD_PROCESS | eff ) Unit
257
+ execFile cmd args opts callback =
258
+ execFileImpl cmd args (convertExecOptions opts) \err stdout' stderr' ->
259
+ callback { error: toMaybe err
260
+ , stdout: stdout'
261
+ , stderr: stderr'
262
+ }
263
+
264
+ foreign import execFileImpl :: forall eff .
265
+ String ->
266
+ Array String ->
267
+ ActualExecOptions ->
268
+ (Nullable Exception.Error -> Buffer -> Buffer -> Eff (cp :: CHILD_PROCESS | eff ) Unit ) ->
269
+ Eff (cp :: CHILD_PROCESS | eff ) Unit
270
+
271
+ foreign import data ActualExecOptions :: *
272
+
273
+ convertExecOptions :: ExecOptions -> ActualExecOptions
274
+ convertExecOptions opts = unsafeCoerce
275
+ { cwd: fromMaybe undefined opts.cwd
276
+ , env: fromMaybe undefined opts.env
277
+ , timeout: fromMaybe undefined opts.timeout
278
+ , maxBuffer: fromMaybe undefined opts.maxBuffer
279
+ , killSignal: fromMaybe undefined opts.killSignal
280
+ , uid: fromMaybe undefined opts.uid
281
+ , gid: fromMaybe undefined opts.gid
282
+ }
283
+
256
284
type ExecOptions =
257
285
{ cwd :: Maybe String
258
286
, env :: Maybe (StrMap String )
0 commit comments