@@ -68,26 +68,6 @@ pub enum CommandEvent {
6868 Terminated ( TerminatedPayload ) ,
6969}
7070
71- macro_rules! get_std_command {
72- ( $self: ident) => { {
73- let mut command = StdCommand :: new( $self. program) ;
74- command. args( & $self. args) ;
75- command. stdout( Stdio :: piped( ) ) ;
76- command. stdin( Stdio :: piped( ) ) ;
77- command. stderr( Stdio :: piped( ) ) ;
78- if $self. env_clear {
79- command. env_clear( ) ;
80- }
81- command. envs( $self. env) ;
82- if let Some ( current_dir) = $self. current_dir {
83- command. current_dir( current_dir) ;
84- }
85- #[ cfg( windows) ]
86- command. creation_flags( CREATE_NO_WINDOW ) ;
87- command
88- } } ;
89- }
90-
9171/// The type to spawn commands.
9272#[ derive( Debug ) ]
9373pub struct Command {
@@ -164,6 +144,26 @@ fn relative_command_path(command: String) -> crate::Result<String> {
164144 }
165145}
166146
147+ impl From < Command > for StdCommand {
148+ fn from ( cmd : Command ) -> StdCommand {
149+ let mut command = StdCommand :: new ( cmd. program ) ;
150+ command. args ( cmd. args ) ;
151+ command. stdout ( Stdio :: piped ( ) ) ;
152+ command. stdin ( Stdio :: piped ( ) ) ;
153+ command. stderr ( Stdio :: piped ( ) ) ;
154+ if cmd. env_clear {
155+ command. env_clear ( ) ;
156+ }
157+ command. envs ( cmd. env ) ;
158+ if let Some ( current_dir) = cmd. current_dir {
159+ command. current_dir ( current_dir) ;
160+ }
161+ #[ cfg( windows) ]
162+ command. creation_flags ( CREATE_NO_WINDOW ) ;
163+ command
164+ }
165+ }
166+
167167impl Command {
168168 /// Creates a new Command for launching the given program.
169169 pub fn new < S : Into < String > > ( program : S ) -> Self {
@@ -252,7 +252,8 @@ impl Command {
252252 /// });
253253 /// ```
254254 pub fn spawn ( self ) -> crate :: api:: Result < ( Receiver < CommandEvent > , CommandChild ) > {
255- let mut command = get_std_command ! ( self ) ;
255+ let encoding = self . encoding ;
256+ let mut command: StdCommand = self . into ( ) ;
256257 let ( stdout_reader, stdout_writer) = pipe ( ) ?;
257258 let ( stderr_reader, stderr_writer) = pipe ( ) ?;
258259 let ( stdin_reader, stdin_writer) = pipe ( ) ?;
@@ -274,14 +275,14 @@ impl Command {
274275 guard. clone ( ) ,
275276 stdout_reader,
276277 CommandEvent :: Stdout ,
277- self . encoding ,
278+ encoding,
278279 ) ;
279280 spawn_pipe_reader (
280281 tx. clone ( ) ,
281282 guard. clone ( ) ,
282283 stderr_reader,
283284 CommandEvent :: Stderr ,
284- self . encoding ,
285+ encoding,
285286 ) ;
286287
287288 spawn ( move || {
0 commit comments