ChildProcessHandle

Node API: Child Process

Object returned from async process spawn/exec methods which provide access to the underlying child process; the object exposes access to the process pid, stdin, stdout, stderr, and terminal exit information, in the form of an exitCode, signalCode, killed state, and so on.

When this object is first created and provided, the child process backing the object may still be alive (in many cases, such as long-running server processes, this is intended behavior).

If the backing process is still alive, terminal information will not be available, and signalCode, exitCode, and related properties return null.

When the process exits, or is terminated through a signal, these fields are filled in by the runtime and become visible to the caller.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val channel: ProcessChannel?

Channel used to communicate with the underlying process.

Link copied to clipboard
open override val connected: Boolean

Whether the subprocess is active and connected.

Link copied to clipboard
open override val exitCode: Int?

Exit code for the process, or null if the subprocess terminated due to a signal.

Link copied to clipboard
open override val killed: Boolean

Whether the process terminated by being killed.

Link copied to clipboard
open override val pid: Long

Process ID for the child process.

Link copied to clipboard
open override val signalCode: String?

Terminal signal code for the process, or null if the subprocess terminated normally.

Link copied to clipboard
open override val stderr: ProcessOutputStream?

Standard error stream for the child process.

Link copied to clipboard
open override val stdin: ProcessInputStream?

Standard input stream for the child process.

Link copied to clipboard
open override val stdio: ProcessIOChannels

Standard error output stream for the child process.

Link copied to clipboard
open override val stdout: ProcessOutputStream?

Standard output stream for the child process.

Functions

Link copied to clipboard
abstract fun addEventListener(type: String, listener: EventListener)
abstract fun addEventListener(type: String, options: AddEventListenerOptions, listener: EventListener)
abstract fun addEventListener(type: String, listener: Value, options: Value?)

Adds a new handler for the type event. Any given listener is added only once per type and per capture option value.

Link copied to clipboard
abstract fun addListener(eventName: String, listener: EventListener)
abstract fun addListener(eventName: String, listener: Value)

Alias for emitter.on(eventName, listener).

Link copied to clipboard
abstract override fun close()
Link copied to clipboard
open override fun disconnect()

Disconnects the child process from the parent.

Link copied to clipboard
abstract fun dispatchEvent(event: Event): Boolean

Dispatches the event to the list of handlers for Event.type.

Link copied to clipboard
abstract fun emit(eventName: String, vararg args: Any?): Boolean

Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments to each.

Link copied to clipboard
abstract fun eventNames(): List<String>

Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbols.

Link copied to clipboard
abstract fun getMaxListeners(): Int

Returns the current max listener value for the emitter.

Link copied to clipboard
open override fun getMember(key: String?): Any?
Link copied to clipboard
open override fun getMemberKeys(): Array<String>
Link copied to clipboard
open override fun hasMember(key: String): Boolean
Link copied to clipboard
open override fun kill(signal: String?)

Kills the child process, using the provided signal.

Link copied to clipboard
abstract fun listenerCount(eventName: String): Int

Returns the number of listeners listening to the event named eventName.

Link copied to clipboard
abstract fun listeners(eventName: String): List<EventListener>

Returns an array listing the listeners for the specified event.

Link copied to clipboard
abstract fun off(eventName: String, listener: Value)

Alias for emitter.removeListener(eventName, listener).

Link copied to clipboard
abstract fun on(eventName: String, listener: EventListener): EventEmitter
abstract fun on(eventName: String, listener: Value): EventEmitter

Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added.

Link copied to clipboard
abstract fun once(eventName: String, listener: EventListener)
abstract fun once(eventName: String, listener: Value)

Adds a one-time listener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.

Link copied to clipboard
abstract fun prependListener(eventName: String, listener: EventListener)
abstract fun prependListener(eventName: String, listener: Value)

Adds the listener function to the beginning of the listeners array for the event named eventName. No checks are made to see if the listener has already been added.

Link copied to clipboard
abstract fun prependOnceListener(eventName: String, listener: EventListener)
abstract fun prependOnceListener(eventName: String, listener: Value)

Adds a one-time listener function for the event named eventName to the beginning of the listener array. The next time eventName is triggered, this listener is removed, and then invoked.

Link copied to clipboard
open override fun putMember(key: String?, value: Value?)
Link copied to clipboard
abstract fun rawListeners(eventName: String): List<EventListener>

Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()).

Link copied to clipboard
open override fun ref(): ProcessChannel
Link copied to clipboard
abstract fun removeAllListeners()

Removes all listeners, or those of the specified eventName.

abstract fun removeAllListeners(eventName: String)

Removes all listeners, or those of the specified eventName.

Link copied to clipboard
abstract fun removeEventListener(type: String, listener: EventListener)
abstract fun removeEventListener(type: String, listener: Value)
abstract fun removeEventListener(type: String, listener: EventListener, options: RemoveEventListenerOptions)
abstract fun removeEventListener(type: String, listener: EventListener, options: Value)
abstract fun removeEventListener(type: String, listener: Value, options: Value)

Removes the listener from the list of handlers for event type.

Link copied to clipboard
abstract fun removeListener(eventName: String, listener: Value)

Removes the specified listener from the listener array for the event named eventName.

Link copied to clipboard
open override fun removeMember(key: String?): Boolean
Link copied to clipboard
open override fun send(message: Value, sendHandle: Value?, options: Value?, callback: Value?): Boolean
Link copied to clipboard
abstract fun setMaxListeners(count: Int)

Sets the maximum number of listeners for the emitter.

Link copied to clipboard
open override fun unref(): ProcessChannel
Link copied to clipboard
open override fun wait(): Int

Non-standard method which waits for process exit.