@@ -118,9 +118,23 @@ pub struct Output {
118118fn relative_command_path ( command : & Path ) -> crate :: Result < PathBuf > {
119119 match platform:: current_exe ( ) ?. parent ( ) {
120120 #[ cfg( windows) ]
121- Some ( exe_dir) => Ok ( exe_dir. join ( command) . with_extension ( "exe" ) ) ,
121+ Some ( exe_dir) => {
122+ let mut command_path = exe_dir. join ( command) ;
123+ let already_exe = command_path. extension ( ) . is_some_and ( |ext| ext == "exe" ) ;
124+ if !already_exe {
125+ // do not use with_extension to retain dots in the command filename
126+ command_path. as_mut_os_string ( ) . push ( ".exe" ) ;
127+ }
128+ Ok ( command_path)
129+ }
122130 #[ cfg( not( windows) ) ]
123- Some ( exe_dir) => Ok ( exe_dir. join ( command) ) ,
131+ Some ( exe_dir) => {
132+ let mut command_path = exe_dir. join ( command) ;
133+ if command_path. extension ( ) . is_some_and ( |ext| ext == "exe" ) {
134+ command_path. set_extension ( "" ) ;
135+ }
136+ Ok ( command_path)
137+ }
124138 None => Err ( crate :: Error :: CurrentExeHasNoParent ) ,
125139 }
126140}
@@ -133,6 +147,10 @@ impl From<Command> for StdCommand {
133147
134148impl Command {
135149 pub ( crate ) fn new < S : AsRef < OsStr > > ( program : S ) -> Self {
150+ log:: debug!(
151+ "Creating sidecar {}" ,
152+ program. as_ref( ) . to_str( ) . unwrap_or( "" )
153+ ) ;
136154 let mut command = StdCommand :: new ( program) ;
137155
138156 command. stdout ( Stdio :: piped ( ) ) ;
@@ -451,9 +469,33 @@ fn spawn_pipe_reader<F: Fn(Vec<u8>) -> CommandEvent + Send + Copy + 'static>(
451469// tests for the commands functions.
452470#[ cfg( test) ]
453471mod tests {
454- #[ cfg( not( windows) ) ]
455472 use super :: * ;
456473
474+ #[ test]
475+ fn relative_command_path_resolves ( ) {
476+ let cwd_parent = platform:: current_exe ( )
477+ . unwrap ( )
478+ . parent ( )
479+ . unwrap ( )
480+ . to_owned ( ) ;
481+ assert_eq ! (
482+ relative_command_path( Path :: new( "Tauri.Example" ) ) . unwrap( ) ,
483+ cwd_parent. join( if cfg!( windows) {
484+ "Tauri.Example.exe"
485+ } else {
486+ "Tauri.Example"
487+ } )
488+ ) ;
489+ assert_eq ! (
490+ relative_command_path( Path :: new( "Tauri.Example.exe" ) ) . unwrap( ) ,
491+ cwd_parent. join( if cfg!( windows) {
492+ "Tauri.Example.exe"
493+ } else {
494+ "Tauri.Example"
495+ } )
496+ ) ;
497+ }
498+
457499 #[ cfg( not( windows) ) ]
458500 #[ test]
459501 fn test_cmd_spawn_output ( ) {
0 commit comments