跳转到内容
Tauri

Shell

访问系统 shell。允许你生成子进程。

支持的平台

This plugin requires a Rust version of at least 1.77.2

Platform Level Notes
windows
linux
macos
android

Only allows to open URLs via open

ios

Only allows to open URLs via open

指定打开应用

如果你正在查找 shell.open 接口的文档,请查看新的指定打开应用插件

设置

请从安装 shell 插件开始。

使用项目的包管理器来添加依赖。

npm run tauri add shell

用法

Shell 插件有 JavaScript 和 Rust 两种版本。

import { Command } from '@tauri-apps/plugin-shell';
// 当设置 `"withGlobalTauri": true`, 你可以使用
// const { Command } = window.__TAURI__.shell;
let result = await Command.create('exec-sh', [
'-c',
"echo 'Hello World!'",
]).execute();
console.log(result);

权限

默认情况下,所有具有潜在危险的插件命令和范围都会被阻止且无法访问。您必须修改 capabilities 文件夹中的配置来启用它们。

参见能力概览以获取更多信息,以及插件的分步导览来调整插件权限。

src-tauri/capabilities/default.json
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "main-capability",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
{
"identifier": "shell:allow-execute",
"allow": [
{
"name": "exec-sh",
"cmd": "sh",
"args": [
"-c",
{
"validator": "\\S+"
}
],
"sidecar": false
}
]
}
]
}

Default Permission

This permission set configures which shell functionality is exposed by default.

Granted Permissions

It allows to use the open functionality without any specific scope pre-configured. It will allow opening http(s)://, tel: and mailto: links.

  • allow-open

Permission Table

Identifier Description

shell:allow-execute

Enables the execute command without any pre-configured scope.

shell:deny-execute

Denies the execute command without any pre-configured scope.

shell:allow-kill

Enables the kill command without any pre-configured scope.

shell:deny-kill

Denies the kill command without any pre-configured scope.

shell:allow-open

Enables the open command without any pre-configured scope.

shell:deny-open

Denies the open command without any pre-configured scope.

shell:allow-spawn

Enables the spawn command without any pre-configured scope.

shell:deny-spawn

Denies the spawn command without any pre-configured scope.

shell:allow-stdin-write

Enables the stdin_write command without any pre-configured scope.

shell:deny-stdin-write

Denies the stdin_write command without any pre-configured scope.


© 2025 Tauri Contributors. CC-BY / MIT