Coder Social home page Coder Social logo

child-process-in-node's Introduction

Child processes in Node js

child_process.spawn(command[,args][,options])

spawn() method spawns a new process using the given command, with command line arguments in args. If omitted, args defaults to an empty array.

child_process.exec(command[,options][,callback])

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.

Difference between spawn() and exec()

child_process.execFile(file[, args][, options][, callback])

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().

child_process.fork(modulePath[, args][, options])

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.

stdio: [stdin, stdout, stderr]

default: pipe

  1. 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.
  2. ignore: stdin = stdout = stderr = null. The subprocess executes and exits. No output is there.
  3. 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.

child-process-in-node's People

Contributors

subhrapaladhi avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.