コンテンツにスキップ
Tauri

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 open

ios

Only allows to open URLs via open

shell.open API のドキュメントをお探しであれば、新しい「Opener プラグイン」の章を参照してください。

はじめに、「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 設定でアクセス権限を変更する必要があります。

詳細については「セキュリティ・レベル 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 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

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.

【※ この日本語版は、「Feb 22, 2025 英語版」に基づいています】


© 2025 Tauri Contributors. CC-BY / MIT