@@ -37,6 +37,10 @@ module Node.ChildProcess
37
37
, ExecOptions
38
38
, ExecResult
39
39
, defaultExecOptions
40
+ , execSync
41
+ , execFileSync
42
+ , ExecSyncOptions
43
+ , defaultExecSyncOptions
40
44
, fork
41
45
, StdIOBehaviour (..)
42
46
, pipe
@@ -47,24 +51,20 @@ module Node.ChildProcess
47
51
import Prelude
48
52
49
53
import Control.Alt ((<|>))
50
- import Effect (Effect )
51
- import Effect.Exception as Exception
52
- import Effect.Exception.Unsafe (unsafeThrow )
53
-
54
54
import Data.Function.Uncurried (Fn2 , runFn2 )
55
55
import Data.Maybe (Maybe (..), fromMaybe )
56
56
import Data.Nullable (Nullable , toNullable , toMaybe )
57
57
import Data.Posix (Pid , Gid , Uid )
58
58
import Data.Posix.Signal (Signal )
59
59
import Data.Posix.Signal as Signal
60
-
60
+ import Effect (Effect )
61
+ import Effect.Exception as Exception
62
+ import Effect.Exception.Unsafe (unsafeThrow )
61
63
import Foreign (Foreign )
62
64
import Foreign.Object (Object )
63
-
64
65
import Node.Buffer (Buffer )
65
66
import Node.FS as FS
66
67
import Node.Stream (Readable , Writable , Stream )
67
-
68
68
import Unsafe.Coerce (unsafeCoerce )
69
69
70
70
-- | A handle for inter-process communication (IPC).
@@ -314,6 +314,79 @@ type ExecResult =
314
314
, error :: Maybe Exception.Error
315
315
}
316
316
317
+ -- | Generally identical to `exec`, with the exception that
318
+ -- | the method will not return until the child process has fully closed.
319
+ -- | Returns: The stdout from the command.
320
+ execSync
321
+ :: String
322
+ -> ExecSyncOptions
323
+ -> Effect Buffer
324
+ execSync cmd opts =
325
+ execSyncImpl cmd (convertExecSyncOptions opts)
326
+
327
+ foreign import execSyncImpl
328
+ :: String
329
+ -> ActualExecSyncOptions
330
+ -> Effect Buffer
331
+
332
+ -- | Generally identical to `execFile`, with the exception that
333
+ -- | the method will not return until the child process has fully closed.
334
+ -- | Returns: The stdout from the command.
335
+ execFileSync
336
+ :: String
337
+ -> Array String
338
+ -> ExecSyncOptions
339
+ -> Effect Buffer
340
+ execFileSync cmd args opts =
341
+ execFileSyncImpl cmd args (convertExecSyncOptions opts)
342
+
343
+ foreign import execFileSyncImpl
344
+ :: String
345
+ -> Array String
346
+ -> ActualExecSyncOptions
347
+ -> Effect Buffer
348
+
349
+ foreign import data ActualExecSyncOptions :: Type
350
+
351
+ convertExecSyncOptions :: ExecSyncOptions -> ActualExecSyncOptions
352
+ convertExecSyncOptions opts = unsafeCoerce
353
+ { cwd: fromMaybe undefined opts.cwd
354
+ , input: fromMaybe undefined opts.input
355
+ , stdio: toActualStdIOOptions opts.stdio
356
+ , env: fromMaybe undefined opts.env
357
+ , timeout: fromMaybe undefined opts.timeout
358
+ , maxBuffer: fromMaybe undefined opts.maxBuffer
359
+ , killSignal: fromMaybe undefined opts.killSignal
360
+ , uid: fromMaybe undefined opts.uid
361
+ , gid: fromMaybe undefined opts.gid
362
+ }
363
+
364
+ type ExecSyncOptions =
365
+ { cwd :: Maybe String
366
+ , input :: Maybe String
367
+ , stdio :: Array (Maybe StdIOBehaviour )
368
+ , env :: Maybe (Object String )
369
+ , timeout :: Maybe Number
370
+ , maxBuffer :: Maybe Int
371
+ , killSignal :: Maybe Signal
372
+ , uid :: Maybe Uid
373
+ , gid :: Maybe Gid
374
+ }
375
+
376
+ defaultExecSyncOptions :: ExecSyncOptions
377
+ defaultExecSyncOptions =
378
+ { cwd: Nothing
379
+ , input: Nothing
380
+ , stdio: pipe
381
+ , env: Nothing
382
+ , timeout: Nothing
383
+ , maxBuffer: Nothing
384
+ , killSignal: Nothing
385
+ , uid: Nothing
386
+ , gid: Nothing
387
+ }
388
+
389
+
317
390
-- | A special case of `spawn` for creating Node.js child processes. The first
318
391
-- | argument is the module to be run, and the second is the argv (command line
319
392
-- | arguments).
0 commit comments