Skip to content

Commit

Permalink
fix: command execution in tauri's Node.js CLI (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Feb 17, 2023
1 parent ae11564 commit 6ce6e1f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changes/refactor-command-output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-mobile": patch
---

Fixed command execution on environments like Node-API.
18 changes: 13 additions & 5 deletions src/bossy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,12 @@ impl Command {
/// Run the command and block until it exits.
pub fn run_and_wait(&mut self) -> Result<ExitStatus> {
log::trace!("running command {:?} and waiting for exit", self.display);
self.set_stdout(os_pipe::dup_stdout().unwrap());
self.set_stderr(os_pipe::dup_stderr().unwrap());
self.run_inner()?.wait()
//self.set_stdout(os_pipe::dup_stdout().unwrap());
//self.set_stderr(os_pipe::dup_stderr().unwrap());
self.inner.status().map_err(|e| Error {
command: self.display.clone(),
cause: Cause::SpawnFailed(e),
})
}

/// Run the command and block until its output is collected. This will
Expand All @@ -361,8 +364,13 @@ impl Command {
log::trace!("running command {:?} and waiting for output", self.display);
self.set_stdout_piped()
.set_stderr_piped()
.run_inner()?
.wait_for_output()
.inner
.output()
.map(|o| Output::new(self.display.clone(), o))
.map_err(|e| Error {
command: self.display.clone(),
cause: Cause::SpawnFailed(e),
})
}

pub fn run_and_wait_for_str<T>(&mut self, f: impl FnOnce(&str) -> T) -> Result<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/os/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn open_file_with(
.with_arg("-a")
.with_args(&[application.as_ref(), path.as_ref()])
.with_env_vars(env.explicit_env())
.run_and_wait()
.run_and_wait_for_output()
.map_err(OpenFileError::BossyLaunchFailed)?;
Ok(())
}
Expand Down

0 comments on commit 6ce6e1f

Please sign in to comment.