@tauri-apps/plugin-shell
Access the system shell. Allows you to spawn child processes and manage files and URLs using their default application.
This API has a scope configuration that forces you to restrict the programs and arguments that can be used.
On the configuration object, open: true
means that the open API can be used with any URL,
as the argument is validated with the ^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+
regex.
You can change that regex by changing the boolean value to a string, e.g. open: ^https://github.com/
.
The plugin permissions object has a scope
field that defines an array of CLIs that can be used.
Each CLI is a configuration object { name: string, cmd: string, sidecar?: bool, args?: boolean | Arg[] }
.
name
: the unique identifier of the command, passed to the Command.create function. If it’s a sidecar, this must be the value defined ontauri.conf.json > bundle > externalBin
.cmd
: the program that is executed on this configuration. If it’s a sidecar, this value is ignored.sidecar
: whether the object configures a sidecar or a system program.args
: the arguments that can be passed to the program. By default no arguments are allowed.true
means that any argument list is allowed.false
means that no arguments are allowed.- otherwise an array can be configured. Each item is either a string representing the fixed argument value
or a
{ validator: string }
that defines a regex validating the argument value.
CLI: git commit -m "the commit message"
Capability:
{ "permissions": [ { "identifier": "shell:allow-execute", "allow": [ { "name": "run-git-commit", "cmd": "git", "args": ["commit", "-m", { "validator": "\\S+" }] } ] } ]}
Usage:
import { Command } from '@tauri-apps/plugin-shell'Command.create('run-git-commit', ['commit', '-m', 'the commit message'])
Trying to execute any API with a program not configured on the scope results in a promise rejection due to denied access.
2.0.0
new Child(pid): Child
Parameter | Type |
---|---|
pid | number |
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L301
Property | Type | Description | Defined in |
---|---|---|---|
pid | number | The child process pid . | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L299 |
kill(): Promise<void>
Kills the child process.
Promise
<void
>
A promise indicating the success or failure of the operation.
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L336
write(data): Promise<void>
Writes data
to the stdin
.
Parameter | Type | Description |
---|---|---|
data | IOPayload | number [] | The message to write, either a string or a byte array. |
Promise
<void
>
A promise indicating the success or failure of the operation.
import { Command } from '@tauri-apps/plugin-shell';const command = Command.create('node');const child = await command.spawn();await child.write('message');await child.write([0, 1, 2, 3, 4, 5]);
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L322
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 Parameter |
---|
O extends IOPayload |
Property | Modifier | Type | Description | Defined in |
---|---|---|---|---|
stderr | readonly | EventEmitter <OutputEvents <O >> | Event emitter for the stderr . Emits the data event. | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L384 |
stdout | readonly | EventEmitter <OutputEvents <O >> | Event emitter for the stdout . Emits the data event. | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L382 |
addListener<N>(eventName, listener): this
Alias for emitter.on(eventName, listener)
.
Type Parameter |
---|
N extends keyof CommandEvents |
Parameter | Type |
---|---|
eventName | N |
listener | (arg ) => void |
this
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L118
execute(): Promise<ChildProcess<O>>
Executes the command as a child process, waiting for it to finish and collecting all of its output.
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
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L530
listenerCount<N>(eventName): number
Returns the number of listeners listening to the event named eventName
.
Type Parameter |
---|
N extends keyof CommandEvents |
Parameter | Type |
---|---|
eventName | N |
number
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L241
off<N>(eventName, listener): this
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 Parameter |
---|
N extends keyof CommandEvents |
Parameter | Type |
---|---|
eventName | N |
listener | (arg ) => void |
this
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L186
on<N>(eventName, listener): this
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 eventName
and 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 Parameter |
---|
N extends keyof CommandEvents |
Parameter | Type |
---|---|
eventName | N |
listener | (arg ) => void |
this
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L147
once<N>(eventName, listener): this
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 Parameter |
---|
N extends keyof CommandEvents |
Parameter | Type |
---|---|
eventName | N |
listener | (arg ) => void |
this
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L169
prependListener<N>(eventName, listener): this
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 eventName
and 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 Parameter |
---|
N extends keyof CommandEvents |
Parameter | Type |
---|---|
eventName | N |
listener | (arg ) => void |
this
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L258
prependOnceListener<N>(eventName, listener): this
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 Parameter |
---|
N extends keyof CommandEvents |
Parameter | Type |
---|---|
eventName | N |
listener | (arg ) => void |
this
2.0.0
EventEmitter
.prependOnceListener
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L280
removeAllListeners<N>(event?): this
Removes all listeners, or those of the specified eventName.
Returns a reference to the EventEmitter
, so that calls can be chained.
Type Parameter |
---|
N extends keyof CommandEvents |
Parameter | Type |
---|---|
event ? | N |
this
2.0.0
EventEmitter
.removeAllListeners
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L206
removeListener<N>(eventName, listener): this
Alias for emitter.off(eventName, listener)
.
Type Parameter |
---|
N extends keyof CommandEvents |
Parameter | Type |
---|---|
eventName | N |
listener | (arg ) => void |
this
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L130
spawn(): Promise<Child>
Executes the command as a child process, returning a handle to it.
A promise resolving to the child process handle.
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L479
Creates a command to execute the given program.
import { Command } from '@tauri-apps/plugin-shell';const command = Command.create('my-app', ['run', 'tauri']);const output = await command.execute();
The program to execute.
It must be configured on tauri.conf.json > plugins > shell > scope
.
static create(program, args?): Command<string>
Creates a command to execute the given program.
Parameter | Type |
---|---|
program | string |
args ? | string | string [] |
Command
<string
>
import { Command } from '@tauri-apps/plugin-shell';const command = Command.create('my-app', ['run', 'tauri']);const output = await command.execute();
The program to execute.
It must be configured on tauri.conf.json > plugins > shell > scope
.
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L406
static create( program, args?,options?): Command<Uint8Array<ArrayBufferLike>>
Creates a command to execute the given program.
Parameter | Type |
---|---|
program | string |
args ? | string | string [] |
options ? | SpawnOptions & object |
Command
<Uint8Array
<ArrayBufferLike
>>
import { Command } from '@tauri-apps/plugin-shell';const command = Command.create('my-app', ['run', 'tauri']);const output = await command.execute();
The program to execute.
It must be configured on tauri.conf.json > plugins > shell > scope
.
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L407
static create( program, args?,options?): Command<string>
Creates a command to execute the given program.
Parameter | Type |
---|---|
program | string |
args ? | string | string [] |
options ? | SpawnOptions |
Command
<string
>
import { Command } from '@tauri-apps/plugin-shell';const command = Command.create('my-app', ['run', 'tauri']);const output = await command.execute();
The program to execute.
It must be configured on tauri.conf.json > plugins > shell > scope
.
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L412
Creates a command to execute the given sidecar program.
import { Command } from '@tauri-apps/plugin-shell';const command = Command.sidecar('my-sidecar');const output = await command.execute();
The program to execute.
It must be configured on tauri.conf.json > plugins > shell > scope
.
static sidecar(program, args?): Command<string>
Creates a command to execute the given sidecar program.
Parameter | Type |
---|---|
program | string |
args ? | string | string [] |
Command
<string
>
import { Command } from '@tauri-apps/plugin-shell';const command = Command.sidecar('my-sidecar');const output = await command.execute();
The program to execute.
It must be configured on tauri.conf.json > plugins > shell > scope
.
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L438
static sidecar( program, args?,options?): Command<Uint8Array<ArrayBufferLike>>
Creates a command to execute the given sidecar program.
Parameter | Type |
---|---|
program | string |
args ? | string | string [] |
options ? | SpawnOptions & object |
Command
<Uint8Array
<ArrayBufferLike
>>
import { Command } from '@tauri-apps/plugin-shell';const command = Command.sidecar('my-sidecar');const output = await command.execute();
The program to execute.
It must be configured on tauri.conf.json > plugins > shell > scope
.
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L439
static sidecar( program, args?,options?): Command<string>
Creates a command to execute the given sidecar program.
Parameter | Type |
---|---|
program | string |
args ? | string | string [] |
options ? | SpawnOptions |
Command
<string
>
import { Command } from '@tauri-apps/plugin-shell';const command = Command.sidecar('my-sidecar');const output = await command.execute();
The program to execute.
It must be configured on tauri.conf.json > plugins > shell > scope
.
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L444
2.0.0
Type Parameter |
---|
E extends Record <string , any > |
new EventEmitter<E>(): EventEmitter<E>
EventEmitter
<E
>
addListener<N>(eventName, listener): this
Alias for emitter.on(eventName, listener)
.
Type Parameter |
---|
N extends string | number | symbol |
Parameter | Type |
---|---|
eventName | N |
listener | (arg ) => void |
this
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L118
listenerCount<N>(eventName): number
Returns the number of listeners listening to the event named eventName
.
Type Parameter |
---|
N extends string | number | symbol |
Parameter | Type |
---|---|
eventName | N |
number
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L241
off<N>(eventName, listener): this
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 Parameter |
---|
N extends string | number | symbol |
Parameter | Type |
---|---|
eventName | N |
listener | (arg ) => void |
this
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L186
on<N>(eventName, listener): this
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 eventName
and 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 Parameter |
---|
N extends string | number | symbol |
Parameter | Type |
---|---|
eventName | N |
listener | (arg ) => void |
this
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L147
once<N>(eventName, listener): this
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 Parameter |
---|
N extends string | number | symbol |
Parameter | Type |
---|---|
eventName | N |
listener | (arg ) => void |
this
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L169
prependListener<N>(eventName, listener): this
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 eventName
and 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 Parameter |
---|
N extends string | number | symbol |
Parameter | Type |
---|---|
eventName | N |
listener | (arg ) => void |
this
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L258
prependOnceListener<N>(eventName, listener): this
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 Parameter |
---|
N extends string | number | symbol |
Parameter | Type |
---|---|
eventName | N |
listener | (arg ) => void |
this
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L280
removeAllListeners<N>(event?): this
Removes all listeners, or those of the specified eventName.
Returns a reference to the EventEmitter
, so that calls can be chained.
Type Parameter |
---|
N extends string | number | symbol |
Parameter | Type |
---|---|
event ? | N |
this
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L206
removeListener<N>(eventName, listener): this
Alias for emitter.off(eventName, listener)
.
Type Parameter |
---|
N extends string | number | symbol |
Parameter | Type |
---|---|
eventName | N |
listener | (arg ) => void |
this
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L130
2.0.0
Type Parameter |
---|
O extends IOPayload |
Property | Type | Description | Defined in |
---|---|---|---|
code | null | number | Exit code of the process. null if the process was terminated by a signal on Unix. | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L94 |
signal | null | number | If the process was terminated by a signal, represents that signal. | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L96 |
stderr | O | The data that the process wrote to stderr . | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L100 |
stdout | O | The data that the process wrote to stdout . | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L98 |
Property | Type | Defined in |
---|---|---|
close | TerminatedPayload | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L345 |
error | string | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L346 |
Type Parameter |
---|
O extends IOPayload |
Property | Type | Defined in |
---|---|---|
data | O | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L350 |
2.0.0
Property | Type | Description | Defined in |
---|---|---|---|
cwd? | string | Current working directory. | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L73 |
encoding? | string | Character encoding for stdout/stderr Since 2.0.0 | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L81 |
env? | Record <string , string > | Environment variables. set to null to clear the process env. | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L75 |
Payload for the Terminated
command event.
Property | Type | Description | Defined in |
---|---|---|---|
code | null | number | Exit code of the process. null if the process was terminated by a signal on Unix. | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L560 |
signal | null | number | If the process was terminated by a signal, represents that signal. | Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L562 |
type IOPayload: string | Uint8Array;
Event payload type
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L566
function open(path, openWith?): Promise<void>
Opens a path or URL with the system’s default app,
or the one specified with openWith
.
The openWith
value must be one of firefox
, google chrome
, chromium
safari
,
open
, start
, xdg-open
, gio
, gnome-open
, kde-open
or wslview
.
Parameter | Type | Description |
---|---|---|
path | string | The path or URL to open. This value is matched against the string regex defined on tauri.conf.json > plugins > shell > open , which defaults to `^((mailto:\w+) |
openWith ? | string | The app to open the file or URL with. Defaults to the system default application for the specified path type. |
Promise
<void
>
import { open } from '@tauri-apps/plugin-shell';// opens the given URL on the default browser:await open('https://github.com/tauri-apps/tauri');// opens the given URL using `firefox`:await open('https://github.com/tauri-apps/tauri', 'firefox');// opens a file using the default program:await open('/path/to/file');
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/shell/guest-js/index.ts#L601
© 2025 Tauri Contributors. CC-BY / MIT