I'm trying to execute a simple echo Hello with the shell plugin with Tauri v2 on Windows. This command needs to be executed when the program starts in the Rust side, so I've tried this:
This is the run function at lib.rs file.
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![greet])
.setup(|app| {
let shell = app.shell();
let output = tauri::async_runtime::block_on(async move {
shell
.command("echo")
.args(["-c", "Hello"])
.output()
.await
.unwrap()
});
if output.status.success() {
println!("Result: {:?}", String::from_utf8(output.stdout));
} else {
println!("Exit with code: {}", output.status.code().unwrap());
}
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
Just trying to recreate what is in the docs. But after I learn how to use the shell plugin, I will use it to open an external program (not a sidecar) with the start /b command in Windows.
To give more context, here's my capabilities/default.json file:
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
"shell:allow-open",
"shell:allow-execute",
"shell:allow-spawn",
"shell:allow-kill",
{
"identifier": "shell:allow-execute",
"allow": [
{
"name": "exec-echo",
"cmd": "echo",
"args": ["/c", "Hello"],
"sidecar": false
}
]
}
]
}
The problem
When I open the program, the error on the image is shown.