mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
This commit is contained in:
committed by
GitHub
parent
5c5c42edb6
commit
9f1d34c288
5
.changes/command-into-stdcommand.md
Normal file
5
.changes/command-into-stdcommand.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": patch
|
||||
---
|
||||
|
||||
Implement `From<api::process::Command> for std::process::Command`.
|
||||
@@ -68,26 +68,6 @@ pub enum CommandEvent {
|
||||
Terminated(TerminatedPayload),
|
||||
}
|
||||
|
||||
macro_rules! get_std_command {
|
||||
($self: ident) => {{
|
||||
let mut command = StdCommand::new($self.program);
|
||||
command.args(&$self.args);
|
||||
command.stdout(Stdio::piped());
|
||||
command.stdin(Stdio::piped());
|
||||
command.stderr(Stdio::piped());
|
||||
if $self.env_clear {
|
||||
command.env_clear();
|
||||
}
|
||||
command.envs($self.env);
|
||||
if let Some(current_dir) = $self.current_dir {
|
||||
command.current_dir(current_dir);
|
||||
}
|
||||
#[cfg(windows)]
|
||||
command.creation_flags(CREATE_NO_WINDOW);
|
||||
command
|
||||
}};
|
||||
}
|
||||
|
||||
/// The type to spawn commands.
|
||||
#[derive(Debug)]
|
||||
pub struct Command {
|
||||
@@ -164,6 +144,26 @@ fn relative_command_path(command: String) -> crate::Result<String> {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Command> for StdCommand {
|
||||
fn from(cmd: Command) -> StdCommand {
|
||||
let mut command = StdCommand::new(cmd.program);
|
||||
command.args(cmd.args);
|
||||
command.stdout(Stdio::piped());
|
||||
command.stdin(Stdio::piped());
|
||||
command.stderr(Stdio::piped());
|
||||
if cmd.env_clear {
|
||||
command.env_clear();
|
||||
}
|
||||
command.envs(cmd.env);
|
||||
if let Some(current_dir) = cmd.current_dir {
|
||||
command.current_dir(current_dir);
|
||||
}
|
||||
#[cfg(windows)]
|
||||
command.creation_flags(CREATE_NO_WINDOW);
|
||||
command
|
||||
}
|
||||
}
|
||||
|
||||
impl Command {
|
||||
/// Creates a new Command for launching the given program.
|
||||
pub fn new<S: Into<String>>(program: S) -> Self {
|
||||
@@ -252,7 +252,8 @@ impl Command {
|
||||
/// });
|
||||
/// ```
|
||||
pub fn spawn(self) -> crate::api::Result<(Receiver<CommandEvent>, CommandChild)> {
|
||||
let mut command = get_std_command!(self);
|
||||
let encoding = self.encoding;
|
||||
let mut command: StdCommand = self.into();
|
||||
let (stdout_reader, stdout_writer) = pipe()?;
|
||||
let (stderr_reader, stderr_writer) = pipe()?;
|
||||
let (stdin_reader, stdin_writer) = pipe()?;
|
||||
@@ -274,14 +275,14 @@ impl Command {
|
||||
guard.clone(),
|
||||
stdout_reader,
|
||||
CommandEvent::Stdout,
|
||||
self.encoding,
|
||||
encoding,
|
||||
);
|
||||
spawn_pipe_reader(
|
||||
tx.clone(),
|
||||
guard.clone(),
|
||||
stderr_reader,
|
||||
CommandEvent::Stderr,
|
||||
self.encoding,
|
||||
encoding,
|
||||
);
|
||||
|
||||
spawn(move || {
|
||||
|
||||
Reference in New Issue
Block a user