Files
archived-tauri-docs/docs/api/js/classes/shell.Command.md
Lorenzo Lewis e8115dca4b i18n (#337)
* Remove French docs (none had been translated yet)
* Move English docs up to be directly under the docs folder (serves as the default)
* Remove old translation files
* Remove references to old translation files in docusaurus.config.js, index.js, partners.js, and showcase.js, swapping in place Docusaurus's Translate HTML element and translate() function
* Remove unused users.js file
* Remove supported-languages.js (this is now contained by default in the docusaurus.config.js file)
* Add translate command to package.json that will auto-generate enabled languages
* Add generated translation files derived from translate (note: this will require re-work on Crowdin)
* Add MIT license to package.json (removes an annoying warning when building)
* Update supported browsers (removes an annoying warning when building)
* Remove t, languages, and language objects from docusaurus.config.js that were referencing the old translation files
* Update netlify.toml to now simply run yarn build (note: this will not yet generated the translations on CI/CD, this will need to be updated later)
2022-01-16 20:38:01 +00:00

4.2 KiB

title, sidebar_label, custom_edit_url, hide_title
title sidebar_label custom_edit_url hide_title
Class: Command Command null true

Class: Command

shell.Command

The entry point for spawning child processes. It emits the close and error events.

example

const command = new Command('node')
command.on('close', data => {
  console.log(`command finished with code ${data.code} and signal ${data.signal}`)
})
command.on('error', error => console.error(`command error: "${error}"`))
command.stdout.on('data', line => console.log(`command stdout: "${line}"`))
command.stderr.on('data', line => console.log(`command stderr: "${line}"`))

const child = await command.spawn()
console.log('pid:', child.pid)

Hierarchy

  • EventEmitter<"close" | "error">

    Command

Constructors

constructor

new Command(program, args?, options?)

Creates a new Command instance.

Parameters

Name Type Default value Description
program string undefined The program to execute.
args string | string[] [] Program arguments.
options? SpawnOptions undefined Spawn options.

Overrides

EventEmitter<'close' | 'error'&gt;.constructor

Defined in

shell.ts:216

Properties

stderr

Readonly stderr: EventEmitter<"data">

Event emitter for the stderr. Emits the data event.

Defined in

shell.ts:207


stdout

Readonly stdout: EventEmitter<"data">

Event emitter for the stdout. Emits the data event.

Defined in

shell.ts:205

Methods

execute

execute(): Promise<ChildProcess>

Executes the command as a child process, waiting for it to finish and collecting all of its output.

example

const output = await new Command('echo', 'message').execute()
assert(output.code === 0)
assert(output.signal === null)
assert(output.stdout === 'message')
assert(output.stderr === '')

Returns

Promise<ChildProcess>

A promise resolving to the child process output.

Defined in

shell.ts:292


on

on(event, handler): EventEmitter<"close" | "error">

Listen to an event from the child process.

Parameters

Name Type Description
event "close" | "error" The event name.
handler (arg: any) => void The event handler.

Returns

EventEmitter<"close" | "error">

The this instance for chained calls.

Inherited from

EventEmitter.on

Defined in

shell.ts:125


spawn

spawn(): Promise<Child>

Executes the command as a child process, returning a handle to it.

Returns

Promise<Child>

A promise resolving to the child process handle.

Defined in

shell.ts:255


sidecar

Static sidecar(program, args?, options?): Command

Creates a command to execute the given sidecar program.

example

const command = Command.sidecar('my-sidecar')
const output = await command.execute()

Parameters

Name Type Default value Description
program string undefined The program to execute.
args string | string[] [] Program arguments.
options? SpawnOptions undefined Spawn options.

Returns

Command

Defined in

shell.ts:240