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

Example

import { Command } from '@tauri-apps/plugin-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);

Since

2.0.0

Type Parameters

Hierarchy (view full)

Properties

stderr: EventEmitter<OutputEvents<O>> = ...

Event emitter for the stderr. Emits the data event.

stdout: EventEmitter<OutputEvents<O>> = ...

Event emitter for the stdout. Emits the data event.

Methods

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

    Returns Promise<ChildProcess<O>>

    A promise resolving to the child process output.

    Example

    import { Command } from '@tauri-apps/plugin-shell';
    const output = await Command.create('echo', 'message').execute();
    assert(output.code === 0);
    assert(output.signal === null);
    assert(output.stdout === 'message');
    assert(output.stderr === '');

    Since

    2.0.0

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

    Type Parameters

    Parameters

    • eventName: N

    Returns number

    Since

    2.0.0

  • 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.

    Type Parameters

    Parameters

    • eventName: N
    • listener: ((arg) => void)

    Returns this

    Since

    2.0.0

  • 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.

    Type Parameters

    Parameters

    • eventName: N
    • listener: ((arg) => void)

    Returns this

    Since

    2.0.0

  • 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.

    Type Parameters

    Parameters

    • eventName: N
    • listener: ((arg) => void)

    Returns this

    Since

    2.0.0

  • 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.

    Type Parameters

    Parameters

    • eventName: N
    • listener: ((arg) => void)

    Returns this

    Since

    2.0.0

  • 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.

    Type Parameters

    Parameters

    • eventName: N
    • listener: ((arg) => void)

    Returns this

    Since

    2.0.0

  • Removes all listeners, or those of the specified eventName.

    Returns a reference to the EventEmitter, so that calls can be chained.

    Type Parameters

    Parameters

    • Optional event: N

    Returns this

    Since

    2.0.0

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

    Returns Promise<Child>

    A promise resolving to the child process handle.

    Since

    2.0.0

  • Creates a command to execute the given program.

    Parameters

    • program: string

      The program to execute. It must be configured on tauri.conf.json > plugins > shell > scope.

    • Optional args: string | string[]

    Returns Command<string>

    Example

    import { Command } from '@tauri-apps/plugin-shell';
    const command = Command.create('my-app', ['run', 'tauri']);
    const output = await command.execute();
  • Creates a command to execute the given program.

    Parameters

    • program: string

      The program to execute. It must be configured on tauri.conf.json > plugins > shell > scope.

    • Optional args: string | string[]
    • Optional options: SpawnOptions & {
          encoding: "raw";
      }

    Returns Command<Uint8Array>

    Example

    import { Command } from '@tauri-apps/plugin-shell';
    const command = Command.create('my-app', ['run', 'tauri']);
    const output = await command.execute();
  • Creates a command to execute the given program.

    Parameters

    • program: string

      The program to execute. It must be configured on tauri.conf.json > plugins > shell > scope.

    • Optional args: string | string[]
    • Optional options: SpawnOptions

    Returns Command<string>

    Example

    import { Command } from '@tauri-apps/plugin-shell';
    const command = Command.create('my-app', ['run', 'tauri']);
    const output = await command.execute();
  • Creates a command to execute the given sidecar program.

    Parameters

    • program: string

      The program to execute. It must be configured on tauri.conf.json > plugins > shell > scope.

    • Optional args: string | string[]

    Returns Command<string>

    Example

    import { Command } from '@tauri-apps/plugin-shell';
    const command = Command.sidecar('my-sidecar');
    const output = await command.execute();
  • Creates a command to execute the given sidecar program.

    Parameters

    • program: string

      The program to execute. It must be configured on tauri.conf.json > plugins > shell > scope.

    • Optional args: string | string[]
    • Optional options: SpawnOptions & {
          encoding: "raw";
      }

    Returns Command<Uint8Array>

    Example

    import { Command } from '@tauri-apps/plugin-shell';
    const command = Command.sidecar('my-sidecar');
    const output = await command.execute();
  • Creates a command to execute the given sidecar program.

    Parameters

    • program: string

      The program to execute. It must be configured on tauri.conf.json > plugins > shell > scope.

    • Optional args: string | string[]
    • Optional options: SpawnOptions

    Returns Command<string>

    Example

    import { Command } from '@tauri-apps/plugin-shell';
    const command = Command.sidecar('my-sidecar');
    const output = await command.execute();