跳到內容
Tauri

Shell

存取系統 Shell。允許您衍生子進程。

支援平台

此外掛程式需要 Rust 版本至少 1.77.2

平台 層級 注意事項
windows
linux
macos
android

僅允許透過 open 開啟 URL

ios

僅允許透過 open 開啟 URL

開啟器

如果您正在尋找 shell.open API 的文件,請改為查看新的Opener 外掛程式

設定

安裝 shell 外掛程式以開始使用。

使用您的專案套件管理器新增依賴項

npm run tauri add 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);

權限

預設情況下,所有潛在危險的外掛程式命令和範圍都會被封鎖且無法存取。您必須修改 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
}
]
}
]
}

預設權限

此權限集設定預設公開哪些 shell 功能。

已授與權限

它允許使用 open 功能,而無需預先設定任何特定範圍。它將允許開啟 http(s)://tel:mailto: 連結。

  • allow-open

權限表

識別碼 描述

shell:allow-execute

啟用 execute 命令,而無需任何預先設定的範圍。

shell:deny-execute

拒絕 execute 命令,而無需任何預先設定的範圍。

shell:allow-kill

啟用 kill 命令,而無需任何預先設定的範圍。

shell:deny-kill

拒絕 kill 命令,而無需任何預先設定的範圍。

shell:allow-open

啟用 open 命令,而無需任何預先設定的範圍。

shell:deny-open

拒絕 open 命令,而無需任何預先設定的範圍。

shell:allow-spawn

啟用 spawn 命令,而無需任何預先設定的範圍。

shell:deny-spawn

拒絕 spawn 命令,而無需任何預先設定的範圍。

shell:allow-stdin-write

啟用 stdin_write 命令,而無需任何預先設定的範圍。

shell:deny-stdin-write

拒絕 stdin_write 命令,而無需任何預先設定的範圍。


© 2025 Tauri 貢獻者。CC-BY / MIT