BufferedProcess Extended

A wrapper which provides standard error/output line buffering for Node’s ChildProcess.

Examples

[BufferedProcess](../BufferedProcess/) = require('atom')

const command = 'ps'
const args = ['-ef']
const stdout = (output) => console.log(output)
const exit = (code) => console.log("ps -ef exited with #[code](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/code)")
const process = new BufferedProcess({command, args, stdout, exit})

Construction

::constructor(options)

Runs the given command by spawning a new child process.

Argument Description

options

An Object with the following keys:

command

The String command to execute.

args

The Array of arguments to pass to the command (optional).

options

Object (optional) The options Object to pass to Node’s ChildProcess.spawn method.

stdout

Function (optional) The callback that receives a single argument which contains the standard output from the command. The callback is called as data is received but it’s buffered to ensure only complete lines are passed until the source stream closes. After the source stream has closed all remaining data is sent in a final call.

data

String

stderr

Function (optional) The callback that receives a single argument which contains the standard error output from the command. The callback is called as data is received but it’s buffered to ensure only complete lines are passed until the source stream closes. After the source stream has closed all remaining data is sent in a final call.

data

String

exit

Function (optional) The callback which receives a single argument containing the exit status.

code

Number

autoStart

Boolean (optional) Whether the command will automatically start when this BufferedProcess is created. Defaults to true. When set to false you must call the start method to start the process.

Event Subscription

::onWillThrowError(callback)

Will call your callback when an error will be raised by the process. Usually this is due to the command not being available or not on the PATH. You can call handle() on the object passed to your callback to indicate that you have handled this error.

Argument Description

callback

Function callback

errorObject

Object

error

Object the error object

handle

Function call this to indicate you have handled the error. The error will not be thrown if this function is called.

Return values

Returns a Disposable

Helper Methods

::kill()

Terminate the process.