diff --git a/crates/nu-command/src/system/run_external.rs b/crates/nu-command/src/system/run_external.rs index 6170cb6c5e..03172d73a2 100644 --- a/crates/nu-command/src/system/run_external.rs +++ b/crates/nu-command/src/system/run_external.rs @@ -187,12 +187,10 @@ impl Command for External { } } else if potential_powershell_script { command.args([ - "-Command", + "-File", &path_to_ps1_executable.unwrap_or_default().to_string_lossy(), ]); - for arg in &args { - command.raw_arg(arg.item.clone()); - } + command.args(args.into_iter().map(|s| s.item)); } else { command.args(args.into_iter().map(|s| s.item)); } diff --git a/crates/nu-command/tests/commands/run_external.rs b/crates/nu-command/tests/commands/run_external.rs index 7c588ad2a8..1c7bcc85a1 100644 --- a/crates/nu-command/tests/commands/run_external.rs +++ b/crates/nu-command/tests/commands/run_external.rs @@ -536,6 +536,25 @@ fn can_run_ps1_files(prefix: &str) { }); } +#[cfg(windows)] +#[apply(run_external_prefixes)] +fn can_run_ps1_files_with_space_in_path(prefix: &str) { + use nu_test_support::fs::Stub::FileWithContent; + Playground::setup("run_a_windows_ps_file", |dirs, sandbox| { + sandbox + .within("path with space") + .with_files(&[FileWithContent( + "foo.ps1", + r#" + Write-Host Hello World + "#, + )]); + + let actual = nu!(cwd: dirs.test().join("path with space"), "{}foo.ps1", prefix); + assert!(actual.out.contains("Hello World")); + }); +} + #[rstest] #[case("^")] #[case("run-external ")]