spawn() method spawns a new process using the given command, with command line arguments in args. If omitted, args defaults to an empty array.
Spawns a shell then executes the command within that shell, buffering any generated output. The command string passed to the exec function is processed directly by the shell and special characters (vary based on shell) need to be dealt with accordingly.
- Child Process in Node.Js
- Node.js Spawn vs. Execute
- Node.js: Difference between spawn and exec of child_process
The child_process.execFile() function is similar to child_process.exec() except that it does not spawn a shell by default. Rather, the specified executable file is spawned directly as a new process making it slightly more efficient than child_process.exec().
The child_process.fork() method is a special case of child_process.spawn() used specifically to spawn new Node.js processes. Like child_process.spawn(), a ChildProcess object is returned. The returned ChildProcess will have an additional communication channel built-in that allows messages to be passed back and forth between the parent and child.
default: pipe
- pipe: Equivalent to subprocess.(stdin/stdout/stderr). The subprocess has it's own stdin/stdout/stderr. Need to add a listener to get the data from the stdin/stdout/stderr.
- ignore: stdin = stdout = stderr = null. The subprocess executes and exits. No output is there.
- inherit: Equivalent to process.(stdin/stdout/stderr). The subprocess uses the parent's stdin/stdout/stderr. No need to add a listner as out put is directly streamed in the parent's console.