nodejs wait for exec in function

前端 未结 4 1596
星月不相逢
星月不相逢 2020-12-11 07:13

I like to integrate exec from nodejs in a custom function to handle all the errors in this one function.

const exec = require(\'child_process\').exec;

funct         


        
4条回答
  •  生来不讨喜
    2020-12-11 07:22

    exec will deal with it in an async fashion, so you should receive a callback or return a promise.

    One thing you could do in order to make it sync is to use execSync instead:

    https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options

    The child_process.execSync() method is generally identical to child_process.exec() with the exception that the method will not return until the child process has fully closed. When a timeout has been encountered and killSignal is sent, the method won't return until the process has completely exited. Note that if the child process intercepts and handles the SIGTERM signal and doesn't exit, the parent process will wait until the child process has exited.

提交回复
热议问题