Shell(シェル・アクセス)
Plugin 説明内容の英語表記部分について Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。
システム・シェルにアクセスします。子プロセスの生成が可能になります。
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 |
| ios | | Only allows to open URLs via |
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 Guest」バインディングをインストールします:
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';// `"withGlobalTauri": true` を使用する場合は、// 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 設定でアクセス権限を変更する必要があります。
詳細については「セキュリティ・レベル 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 } ] } ]}Default Permission
This permission set configures which shell functionality is exposed by default.
Granted Permissions
It allows to use the open functionality with a reasonable
scope pre-configured. It will allow opening http(s)://,
tel: and mailto: links.
This default permission set includes the following:
allow-open
Permission Table
| Identifier | Description |
|---|---|
|
|
Enables the execute command without any pre-configured scope. |
|
|
Denies the execute command without any pre-configured scope. |
|
|
Enables the kill command without any pre-configured scope. |
|
|
Denies the kill command without any pre-configured scope. |
|
|
Enables the open command without any pre-configured scope. |
|
|
Denies the open command without any pre-configured scope. |
|
|
Enables the spawn command without any pre-configured scope. |
|
|
Denies the spawn command without any pre-configured scope. |
|
|
Enables the stdin_write command without any pre-configured scope. |
|
|
Denies the stdin_write command without any pre-configured scope. |
【※ この日本語版は、「Feb 22, 2025 英語版」に基づいています】
© 2025 Tauri Contributors. CC-BY / MIT