node. JS Learning Note (5)-About child_process module

Source: Internet
Author: User

Child_process is a more important module for node, which enables the creation of multi-threading to take advantage of multicore CPUs.

This module provides four functions for creating child processes.

Spawn, exec, execfile, fork.

Spawn is the most primitive function to create a subprocess, and the remaining three is a different encapsulation of the function.

Spawn does not support callback functions.

Both exec and execfile support callback functions. The difference is that the latter does not have to start a separate shell, which is relatively lightweight. Let's take execfile example (open the bat file stored in a fixed position, execute the command line of the file) (Pro-test pass):

1 varChild_process = require (' child_process '));2 //Invoke execution File3 varOpenapp =function(){4Child_process.execfile (' D:/testweb/1.bat ',NULL, {cwd: ' d:/'},function(error,stdout,stderr) {5         if(Error!==NULL) {6Console.log (' EXEC error: ' +error);7         }8     });9 }Ten  OneOpenapp ();

The bat file is a fun thing to do, and there will be a post of bat file in the back. ^_^

Resources:

http://my.oschina.net/u/252343/blog/185998

https://www.byvoid.com/zhs/blog/node-child-process-ipc/

Official documents:

Http://nodejs.org/api/child_process.html

node. JS Learning Note (5)-About child_process module

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.