@@ -483,6 +483,19 @@ fn raw_stream_bytes<'a>(request: &'a Request<'_>) -> Result<&'a [u8], String> {
483483 Ok(bytes)
484484}
485485
486+fn write_native_stream(
487+ mut stream: impl Write,
488+ text: String,
489+ stream_name: &str,
490+) -> Result<(), String> {
491+ stream
492+ .write_all(text.as_bytes())
493+ .map_err(|error| format!("Cannot write application {stream_name}: {error}"))?;
494+ stream
495+ .flush()
496+ .map_err(|error| format!("Cannot flush application {stream_name}: {error}"))
497+}
498+
486499fn take_streams(streams: &Streams, owner: Option<&str>) -> Vec<Arc<Stream>> {
487500 let mut active = streams.active.lock();
488501 let ids: Vec<String> = active
@@ -527,6 +540,26 @@ async fn run(
527540 .map_err(|error| format!("Bundled process worker failed: {error}"))?
528541}
529542
543+#[tauri::command]
544+async fn stdout(text: String) -> Result<(), String> {
545+ tauri::async_runtime::spawn_blocking(move || {
546+ let native_stdout = io::stdout();
547+ write_native_stream(native_stdout.lock(), text, "stdout")
548+ })
549+ .await
550+ .map_err(|error| format!("Bundled process worker failed: {error}"))?
551+}
552+
553+#[tauri::command]
554+async fn stderr(text: String) -> Result<(), String> {
555+ tauri::async_runtime::spawn_blocking(move || {
556+ let native_stderr = io::stderr();
557+ write_native_stream(native_stderr.lock(), text, "stderr")
558+ })
559+ .await
560+ .map_err(|error| format!("Bundled process worker failed: {error}"))?
561+}
562+
530563#[tauri::command]
531564fn spawn<R: Runtime>(
532565 process: State<'_, BundledProcess>,
@@ -602,7 +635,9 @@ async fn cancel<R: Runtime>(
602635pub fn init<R: Runtime>(executables: &[&str]) -> TauriPlugin<R> {
603636 let executables: Vec<String> = executables.iter().map(|name| (*name).to_owned()).collect();
604637 Builder::new("bundled-process")
605− .invoke_handler(tauri::generate_handler![run, spawn, write, finish, cancel])
638+ .invoke_handler(tauri::generate_handler![
639+ run, spawn, write, finish, cancel, stdout, stderr
640+ ])
606641 .setup(move |app, _| {
607642 for name in &executables {
608643 validate_basename(name)