@tauri-apps/plugin-shell - v2.3.0
    Preparing search index...

    Class Command<O>

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

    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);

    2.0.0

    Type Parameters

    Hierarchy (View Summary)

    Index

    Properties

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

    Event emitter for the stdout. Emits the data event.

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

    Event emitter for the stderr. Emits the data event.

    Methods

    • 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

      Returns this

      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

      Returns this

      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

      Returns this

      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

      • Optionalevent: N

      Returns this

      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

      Returns this

      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

      Returns this

      2.0.0

    • Parameters

      • program: string
      • Optionalargs: string | string[]

      Returns Command<string>

    • Parameters

      • program: string
      • Optionalargs: string | string[]
      • Optionaloptions: SpawnOptions & { encoding: "raw" }

      Returns Command<Uint8Array<ArrayBufferLike>>

    • Parameters

      • program: string
      • Optionalargs: string | string[]
      • Optionaloptions: SpawnOptions

      Returns Command<string>

    • Parameters

      • program: string
      • Optionalargs: string | string[]

      Returns Command<string>

    • Parameters

      • program: string
      • Optionalargs: string | string[]
      • Optionaloptions: SpawnOptions & { encoding: "raw" }

      Returns Command<Uint8Array<ArrayBufferLike>>

    • Parameters

      • program: string
      • Optionalargs: string | string[]
      • Optionaloptions: SpawnOptions

      Returns Command<string>

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

      Returns Promise<Child>

      A promise resolving to the child process handle.

      2.0.0

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

      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 === '');

      2.0.0