Object built-in object

Object ChildProcess

Child process object

1 2
var child_process = require("child_process"); var child = child_process.spawn("ls");

Inheritance

#lineWidth: 1.5 #font: Helvetica,sans-Serif #fontSize: 10 #leading: 1.6 #.this: fill=lightgray #.class: fill=white [<class>object|toString();toJSON()] [<class>EventEmitter|new EventEmitter()|EventEmitter|defaultMaxListeners|on();addListener();prependListener();once();prependOnceListener();off();removeListener();removeAllListeners();setMaxListeners();getMaxListeners();listeners();listenerCount();eventNames();emit()] [<this>ChildProcess|pid;exitCode;stdin;stdout;stderr;onexit|kill();join()] [object] <:- [EventEmitter] [EventEmitter] <:- [ChildProcess] EventEmitter new EventEmitter() EventEmitter defaultMaxListeners on() addListener() prependListener() once() prependOnceListener() off() removeListener() removeAllListeners() setMaxListeners() getMaxListeners() listeners() listenerCount() eventNames() emit() ChildProcess pid exitCode stdin stdout stderr onexit kill() join() object toString() toJSON()

Static properties

defaultMaxListeners

Integer, the default global maximum number of listeners

1
static Integer ChildProcess.defaultMaxListeners;

Member attributes

pid

Integer, read the id of the process pointed to by the current object

1
readonly Integer ChildProcess.pid;

exitCode

Integer, query and set the exit code of the current process

1
readonly Integer ChildProcess.exitCode;

stdin

Stream, Read the standard input object of the process pointed to by the current object

1
readonly Stream ChildProcess.stdin;

stdout

Stream, Read the standard output object of the process pointed to by the current object

1
readonly Stream ChildProcess.stdout;

stderr

Stream, Read the standard error object of the process pointed to by the current object

1
readonly Stream ChildProcess.stderr;

onexit

Function, query and bind process exit event, equivalent to on("exit", func);

1
Function ChildProcess.onexit;

Member function

kill

Kill the process pointed to by the current object and pass the signal

1
ChildProcess.kill(Integer signal);

Call parameters:

  • signal: Integer, the signal passed

join

Wait for the end of the process pointed to by the current object, and return the process end code

1
ChildProcess.join() async;

Return result:

  • End code of the process

on

Bind an event handler to the object

1 2
Object ChildProcess.on(String ev, Function func);

Call parameters:

  • ev: String, specify the name of the event
  • func: Function, specify event processing function

Return result:

  • Object, Return the event object itself, which is convenient for chain call

Bind an event handler to the object

1
Object ChildProcess.on(Object map);

Call parameters:

  • map: Object, specify the event mapping relationship, the object property name will be used as the event name, and the property value will be used as the event processing function

Return result:

  • Object, Return the event object itself, which is convenient for chain call

addListener

Bind an event handler to the object

1 2
Object ChildProcess.addListener(String ev, Function func);

Call parameters:

  • ev: String, specify the name of the event
  • func: Function, specify event processing function

Return result:

  • Object, Return the event object itself, which is convenient for chain call

Bind an event handler to the object

1
Object ChildProcess.addListener(Object map);

Call parameters:

  • map: Object, specify the event mapping relationship, the object property name will be used as the event name, and the property value will be used as the event processing function

Return result:

  • Object, Return the event object itself, which is convenient for chain call

prependListener

Bind an event handler to the start of the object

1 2
Object ChildProcess.prependListener(String ev, Function func);

Call parameters:

  • ev: String, specify the name of the event
  • func: Function, specify event processing function

Return result:

  • Object, Return the event object itself, which is convenient for chain call

Bind an event handler to the start of the object

1
Object ChildProcess.prependListener(Object map);

Call parameters:

  • map: Object, specify the event mapping relationship, the object property name will be used as the event name, and the property value will be used as the event processing function

Return result:

  • Object, Return the event object itself, which is convenient for chain call

once

Bind a one-time event processing function to the object, the one-time processing function will only be triggered once

1 2
Object ChildProcess.once(String ev, Function func);

Call parameters:

  • ev: String, specify the name of the event
  • func: Function, specify event processing function

Return result:

  • Object, Return the event object itself, which is convenient for chain call

Bind a one-time event processing function to the object, the one-time processing function will only be triggered once

1
Object ChildProcess.once(Object map);

Call parameters:

  • map: Object, specify the event mapping relationship, the object property name will be used as the event name, and the property value will be used as the event processing function

Return result:

  • Object, Return the event object itself, which is convenient for chain call

prependOnceListener

Bind an event handler to the start of the object

1 2
Object ChildProcess.prependOnceListener(String ev, Function func);

Call parameters:

  • ev: String, specify the name of the event
  • func: Function, specify event processing function

Return result:

  • Object, Return the event object itself, which is convenient for chain call

Bind an event handler to the start of the object

1
Object ChildProcess.prependOnceListener(Object map);

Call parameters:

  • map: Object, specify the event mapping relationship, the object property name will be used as the event name, and the property value will be used as the event processing function

Return result:

  • Object, Return the event object itself, which is convenient for chain call

off

Cancel the specified function from the object processing queue

1 2
Object ChildProcess.off(String ev, Function func);

Call parameters:

  • ev: String, specify the name of the event
  • func: Function, specify event processing function

Return result:

  • Object, Return the event object itself, which is convenient for chain call

Cancel all functions in the object processing queue

1
Object ChildProcess.off(String ev);

Call parameters:

  • ev: String, specify the name of the event

Return result:

  • Object, Return the event object itself, which is convenient for chain call

Cancel the specified function from the object processing queue

1
Object ChildProcess.off(Object map);

Call parameters:

  • map: Object, specify the event mapping relationship, the object property name is used as the event name, and the property value is used as the event processing function

Return result:

  • Object, Return the event object itself, which is convenient for chain call

removeListener

Cancel the specified function from the object processing queue

1 2
Object ChildProcess.removeListener(String ev, Function func);

Call parameters:

  • ev: String, specify the name of the event
  • func: Function, specify event processing function

Return result:

  • Object, Return the event object itself, which is convenient for chain call

Cancel all functions in the object processing queue

1
Object ChildProcess.removeListener(String ev);

Call parameters:

  • ev: String, specify the name of the event

Return result:

  • Object, Return the event object itself, which is convenient for chain call

Cancel the specified function from the object processing queue

1
Object ChildProcess.removeListener(Object map);

Call parameters:

  • map: Object, specify the event mapping relationship, the object property name is used as the event name, and the property value is used as the event processing function

Return result:

  • Object, Return the event object itself, which is convenient for chain call

removeAllListeners

Cancel all listeners of all events from the object processing queue. If an event is specified, remove all listeners of the specified event.

1
Object ChildProcess.removeAllListeners(String ev);

Call parameters:

  • ev: String, specify the name of the event

Return result:

  • Object, Return the event object itself, which is convenient for chain call

Cancel all listeners of all events from the object processing queue. If an event is specified, remove all listeners of the specified event.

1
Object ChildProcess.removeAllListeners(Array evs = []);

Call parameters:

  • evs: Array, specify the name of the event

Return result:

  • Object, Return the event object itself, which is convenient for chain call

setMaxListeners

The default limit of the number of listeners, only for compatibility

1
ChildProcess.setMaxListeners(Integer n);

Call parameters:

  • n: Integer, specify the number of events

getMaxListeners

Get the default limit of the number of listeners, only for compatibility

1
Integer ChildProcess.getMaxListeners();

Return result:

  • Integer, Return to the default limit number

listeners

Array of listeners for the specified event of the query object

1
Array ChildProcess.listeners(String ev);

Call parameters:

  • ev: String, specify the name of the event

Return result:

  • Array, Returns an array of listeners for the specified event

listenerCount

The number of listeners for the specified event of the query object

1
Integer ChildProcess.listenerCount(String ev);

Call parameters:

  • ev: String, specify the name of the event

Return result:

  • Integer, Returns the number of listeners for the specified event

eventNames

Query the event name of the listener

1
Array ChildProcess.eventNames();

Return result:

  • Array, Returns an array of event names

emit

Trigger an event actively

1 2
Boolean ChildProcess.emit(String ev, ...args);

Call parameters:

  • ev: String, event name
  • args: ..., event parameters, which will be passed to the event handler

Return result:

  • Boolean, Return to the event trigger state, return true if there is a response event, otherwise return false

toString

Returns the string representation of the object, generally returns "[Native Object]", the object can be re-implemented according to its own characteristics

1
String ChildProcess.toString();

Return result:

  • String, Returns the string representation of the object

toJSON

Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object

1
Value ChildProcess.toJSON(String key = "");

Call parameters:

  • key: String, unused

Return result:

  • Value, Returns a value containing JSON serializable