Command
이 콘텐츠는 아직 번역되지 않았습니다.
Module @netwiv/api/plugins/shell · Kind Class
import { Command } from '@netwiv/api/plugins/shell';The entry point for spawning child processes.
It emits the close and error events.
Constructor
Section titled “Constructor”new Command<O extends IOPayload>()Static members
Section titled “Static members”create
Section titled “create”create(program: string, args?: string | string[] | undefined): Command<string>create(program: string, args?: string | string[] | undefined, options?: (SpawnOptions & { encoding: "raw"; }) | undefined): Command<Uint8Array<ArrayBufferLike>>create(program: string, args?: string | string[] | undefined, options?: SpawnOptions | undefined): Command<string>sidecar
Section titled “sidecar”sidecar(program: string, args?: string | string[] | undefined): Command<string>sidecar(program: string, args?: string | string[] | undefined, options?: (SpawnOptions & { encoding: "raw"; }) | undefined): Command<Uint8Array<ArrayBufferLike>>sidecar(program: string, args?: string | string[] | undefined, options?: SpawnOptions | undefined): Command<string>Instance members
Section titled “Instance members”addListener
Section titled “addListener”addListener<N>(eventName: N, listener: (arg: CommandEvents[N]): void) => Command<O>Alias for emitter.on(eventName, listener).
execute
Section titled “execute”execute(): Promise<ChildProcess<O>>Executes the command as a child process, waiting for it to finish and collecting all of its output.
Example
import { Command } from '@netwiv/api/plugins/shell';const output = await Command.create('echo', 'message').execute();assert(output.code === 0);assert(output.signal === null);assert(output.stdout === 'message');assert(output.stderr === '');listenerCount
Section titled “listenerCount”listenerCount<N>(eventName: N): numberReturns the number of listeners listening to the event named eventName.
off<N>(eventName: N, listener: (arg: CommandEvents[N]): void) => Command<O>Removes the all specified listener from the listener array for the event eventName
Returns a reference to the EventEmitter, so that calls can be chained.
on<N>(eventName: N, listener: (arg: CommandEvents[N]): void) => Command<O>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. Multiple calls passing the same combination of eventNameand listener will result in the listener being added, and called, multiple
times.
Returns a reference to the EventEmitter, so that calls can be chained.
once<N>(eventName: N, listener: (arg: CommandEvents[N]): void) => Command<O>Adds a one-timelistener function for the event named eventName. The
next time eventName is triggered, this listener is removed and then invoked.
Returns a reference to the EventEmitter, so that calls can be chained.
prependListener
Section titled “prependListener”prependListener<N>(eventName: N, listener: (arg: CommandEvents[N]): void) => Command<O>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. Multiple calls passing the same combination of eventNameand listener will result in the listener being added, and called, multiple
times.
Returns a reference to the EventEmitter, so that calls can be chained.
prependOnceListener
Section titled “prependOnceListener”prependOnceListener<N>(eventName: N, listener: (arg: CommandEvents[N]): void) => Command<O>Adds a one-timelistener function for the event named eventName to the_beginning_ of the listeners array. The next time eventName is triggered, this
listener is removed, and then invoked.
Returns a reference to the EventEmitter, so that calls can be chained.
removeAllListeners
Section titled “removeAllListeners”removeAllListeners<N>(event?: N | undefined): Command<O>Removes all listeners, or those of the specified eventName.
Returns a reference to the EventEmitter, so that calls can be chained.
removeListener
Section titled “removeListener”removeListener<N>(eventName: N, listener: (arg: CommandEvents[N]): void) => Command<O>Alias for emitter.off(eventName, listener).
spawn(): Promise<Child>Executes the command as a child process, returning a handle to it.
stderr
Section titled “stderr”readonly stderr: EventEmitter<OutputEvents<O>>Event emitter for the stderr. Emits the data event.
stdout
Section titled “stdout”readonly stdout: EventEmitter<OutputEvents<O>>Event emitter for the stdout. Emits the data event.
Example
Section titled “Example”import { Command } from '@netwiv/api/plugins/shell';const command = Command.create('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);Upstream since 2.0.0
Descriptions come from the pinned @tauri-apps/plugin-shell@2.3.6 declarations (MIT OR Apache-2.0); imports are shown with @netwiv/api paths.