Shell
访问系统 shell。允许你生成子进程。
此插件需要 Rust 版本至少为 **1.77.2**
| 平台 | 级别 | 备注 |
|---|---|---|
| windows | ||
| linux | ||
| macos | ||
| android | | 仅允许通过 |
| ios | | 仅允许通过 |
如果你正在查找 shell.open API 的文档,请查看新的 Opener 插件。
安装 shell 插件以开始使用。
使用你的项目包管理器添加依赖项
npm run tauri add shellyarn run tauri add shellpnpm tauri add shelldeno task tauri add shellbun tauri add shellcargo tauri add shell-
在
src-tauri文件夹中运行以下命令,将插件添加到项目的Cargo.toml依赖项中cargo add tauri-plugin-shell -
修改
lib.rs以初始化插件src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().plugin(tauri_plugin_shell::init()).run(tauri::generate_context!()).expect("error while running tauri application");} -
使用您首选的 JavaScript 包管理器安装 JavaScript 访客绑定
npm install @tauri-apps/plugin-shellyarn add @tauri-apps/plugin-shellpnpm add @tauri-apps/plugin-shelldeno add npm:@tauri-apps/plugin-shellbun add @tauri-apps/plugin-shell
shell 插件支持 JavaScript 和 Rust。
import { Command } from '@tauri-apps/plugin-shell';// when using `"withGlobalTauri": true`, you may use// const { Command } = window.__TAURI__.shell;
let result = await Command.create('exec-sh', [ '-c', "echo 'Hello World!'",]).execute();console.log(result);use tauri_plugin_shell::ShellExt;
let shell = app_handle.shell();let output = tauri::async_runtime::block_on(async move { shell .command("echo") .args(["Hello from Rust!"]) .output() .await .unwrap()});if output.status.success() { println!("Result: {:?}", String::from_utf8(output.stdout));} else { println!("Exit with code: {}", output.status.code().unwrap());}默认情况下,所有潜在危险的插件命令和范围都被阻止,无法访问。您必须修改 capabilities 配置中的权限才能启用这些功能。
有关更多信息,请参阅功能概述,并参阅分步指南以使用插件权限。
{ "$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 } ] } ]}默认权限
此权限集配置默认公开哪些 shell 功能。
已授予权限
它允许使用预配置了合理作用域的 open 功能。它将允许打开 http(s)://、tel: 和 mailto: 链接。
此默认权限集包括以下内容
allow-open
权限表
| 标识符 | 描述 |
|---|---|
|
|
启用 execute 命令,且无需任何预配置的作用域。 |
|
|
禁用 execute 命令,且无需任何预配置的作用域。 |
|
|
启用 kill 命令,且无需任何预配置的作用域。 |
|
|
禁用 kill 命令,且无需任何预配置的作用域。 |
|
|
启用打开命令,不带任何预配置范围。 |
|
|
禁用打开命令,不带任何预配置范围。 |
|
|
启用 spawn 命令,且无需任何预配置的作用域。 |
|
|
禁用 spawn 命令,且无需任何预配置的作用域。 |
|
|
启用 stdin_write 命令,且无需任何预配置的作用域。 |
|
|
禁用 stdin_write 命令,且无需任何预配置的作用域。 |
© 2026 Tauri 贡献者。CC-BY / MIT