node. JS Learning Notes under Windows (8)---process management processes

Source: Internet
Author: User

process is a global built-in object that can be accessed from anywhere in your code, which represents the operating system process object that hosts our node. js code.

Process objects can be used to intercept events such as exceptions, exits, and so on, to get information about the process's current directory, environment variables, memory consumption, and to perform operations such as process exit, working directory switching, etc.

1. When we want to view the current directory of the application, we can use the CWD function:

PROCESS.CWD ();

2. If you need to change the application directory, you should use the ChDir function:

Process.chdir (' directory name ');

3.stdout is the standard output stream, which is the function of printing content to the output device, Console.log is encapsulated it:

Process.stdout.write (' content to output ');

The 4.stderr is the standard error stream, which is similar to stdout, but it is used to print error messages that we can use to capture error messages:

Process.stderr.write (' content to output ');

5.stdin is the input stream of the process, and we can get the input by registering the event:

// to get the input by registering an event function  // Gets the contents of the input stream  var chunk = process.stdin.read ()  ; if NULL     {// output data+ The contents of the input stream    process.stdout.write (' data: ' + chunk);  }}); 

6. If you need to kill the process within the program, exit the program, you can use the Exit Function:

// The code for the parameter is returned after exit, and if omitted, 0process.exit (code) is returned by default;

7. Get stdout Content: Add registration Events

Process.stdout.on (' data ',function(data) {  console.log (data);});

8. In the content of our input and output when there is a Chinese language, the problem may be garbled, this is due to different coding, so in this case you need to set the code for the stream:

Process.stdin.setEncoding (' UTF8 ');p rocess.stdout.setEncoding (' UTF8 ');p rocess.stderr.setEncoding ( ' UTF8 ');

9. More Process Usage:

http://nodeapi.ucdok.com/#/api/process.htmlhttp://nodejs.cn/api/process

node. JS Learning Notes under Windows (8)---process management processes

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.