@@ -37,6 +37,10 @@ module Node.ChildProcess
3737 , ExecOptions
3838 , ExecResult
3939 , defaultExecOptions
40+ , execSync
41+ , execFileSync
42+ , ExecSyncOptions
43+ , defaultExecSyncOptions
4044 , fork
4145 , StdIOBehaviour (..)
4246 , pipe
@@ -47,24 +51,20 @@ module Node.ChildProcess
4751import Prelude
4852
4953import Control.Alt ((<|>))
50- import Effect (Effect )
51- import Effect.Exception as Exception
52- import Effect.Exception.Unsafe (unsafeThrow )
53-
5454import Data.Function.Uncurried (Fn2 , runFn2 )
5555import Data.Maybe (Maybe (..), fromMaybe )
5656import Data.Nullable (Nullable , toNullable , toMaybe )
5757import Data.Posix (Pid , Gid , Uid )
5858import Data.Posix.Signal (Signal )
5959import Data.Posix.Signal as Signal
60-
60+ import Effect (Effect )
61+ import Effect.Exception as Exception
62+ import Effect.Exception.Unsafe (unsafeThrow )
6163import Foreign (Foreign )
6264import Foreign.Object (Object )
63-
6465import Node.Buffer (Buffer )
6566import Node.FS as FS
6667import Node.Stream (Readable , Writable , Stream )
67-
6868import Unsafe.Coerce (unsafeCoerce )
6969
7070-- | A handle for inter-process communication (IPC).
@@ -314,6 +314,79 @@ type ExecResult =
314314 , error :: Maybe Exception.Error
315315 }
316316
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+
317390-- | A special case of `spawn` for creating Node.js child processes. The first
318391-- | argument is the module to be run, and the second is the argv (command line
319392-- | arguments).
0 commit comments