Skip to content

fix running file-associated scripts with ./ paths on Windows (#19584) - #19636

Merged
fdncred merged 3 commits into
nushell:mainfrom
iamsiddhesh-dev:fix/run-external-forward-slash-script
Nov 23, 2026
Merged

fdncred merged 3 commits into
nushell:mainfrom
iamsiddhesh-dev:fix/run-external-forward-slash-script

Conversation

@iamsiddhesh-dev

@iamsiddhesh-dev iamsiddhesh-dev commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #19584.

On Windows, a script that runs through its file association (for example a .nu, .py or .vbs file whose extension is in PATHEXT) worked as .\script.nu but failed as ./script.nu:

> ./test.nu
'.' is not recognized as an internal or external command,
operable program or batch file.

Cause: for these scripts run-external launches cmd.exe /D /C <name> so Windows applies the file association. The name was passed exactly as typed, and cmd.exe treats / as a switch character, so it read ./test.nu as the command . followed by the switch /test.nu.

Fix: for file-associated scripts, the name as typed is normalized before it's handed to cmd.exe. The new helper cmd_script_path re-joins the name's path components, which turns every / into \ and drops redundant . components while keeping a leading ., e.g. ./sub/./test.nu → .\sub\test.nu. Only the typed name reaches cmd.exe, never the cwd or a PATH directory, so spaces or characters like & in those directories can't affect cmd.exe's parsing.

CMD internal commands (echo, assoc, start, …) still receive the name as typed, so their behaviour is unchanged. .exe, .com, .bat, .cmd and .ps1 files don't go through this code path.

Before / after

Tested on Windows 10 Pro 19045 with .vbs files, which Windows associates with WScript by default (.VBS is in the default PATHEXT). The test script writes a marker file, so RAN means it really executed.

Before (0.116.1 release; main at 594dd47 behaves the same):

.> .\hello.vbs                     => RAN
.> ./hello.vbs                     => FAILED '.' is not recognized as an internal or external command,
.> ./hello                         => FAILED '.' is not recognized as an internal or external command,
.> ./sub/hello.vbs                 => FAILED '.' is not recognized as an internal or external command,
.> ./sub/./hello.vbs               => FAILED '.' is not recognized as an internal or external command,
.> "./sub dir/hello.vbs"           => RAN
John Doe> .\hello.vbs "a b"        => RAN
John Doe> ./hello.vbs "a b"        => FAILED '.' is not recognized as an internal or external command,
R&D> .\hello.vbs                   => RAN
x&whoami&y> .\hello.vbs            => RAN
^echo cmd-builtin-ok               => cmd-builtin-ok

After (this PR):

.> .\hello.vbs                     => RAN
.> ./hello.vbs                     => RAN
.> ./hello                         => RAN
.> ./sub/hello.vbs                 => RAN
.> ./sub/./hello.vbs               => RAN
.> "./sub dir/hello.vbs"           => RAN
John Doe> .\hello.vbs "a b"        => RAN
John Doe> ./hello.vbs "a b"        => RAN
R&D> .\hello.vbs                   => RAN
x&whoami&y> .\hello.vbs            => RAN
^echo cmd-builtin-ok               => cmd-builtin-ok

Tests

  • New Windows integration tests in crates/nu-command/tests/commands/run_external.rs (mod file_association), using .vbs (default WScript association, no registry change). Each prefix (bare, ^, run-external) × script is its own rstest case:
    • can_run_file_associated_scripts_with_forward_slashes: ./hello.vbs, ./hello, ./sub/hello.vbs, ./sub/./hello.vbs, .\sub\hello.vbs (15 cases)
    • can_run_file_associated_scripts_in_dirs_with_cmd_special_chars: cwd John Doe / R&D, with .\hello.vbs, ./hello.vbs, .\hello.vbs "a b" (18 cases)
    • Checked that they catch the bugs: against main the 18 forward-slash cases fail, and against the first version of this PR (resolved path) the special-chars cases fail.
  • Windows-only unit test cmd_script_path_uses_backslashes (7 rstest cases) for the normalization itself.
  • Ran locally on Windows:
    • cargo fmt --all -- --check
    • cargo clippy -p nu-command --all-targets -- -D warnings -D clippy::unwrap_used -D clippy::unchecked_time_subtraction
    • cargo test -p nu-command --lib run_external (10 passed)
    • cargo test -p nu-command --test tests -- commands::run_external (124 passed, 3 ignored Linux-only)

User-facing changes (Release notes)

Fixed an issue on Windows where running a file-associated script with a forward-slash path such as ./script.nu failed with '.' is not recognized as an internal or external command, while .\script.nu worked.

Additional notes

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review overview

🟡 Changes recommended

The ./script.nu fix works: on Windows, ./hello.nu, ./hello and ./sub/hello.nu all run through the .nu association on the branch. Handing cmd.exe the resolved path also hands it the cwd, though, and that breaks scripts in directories that 0.117.1 handles fine.

Findings: 1 High severity · 0 Medium severity · 1 Low severity

Open (2)

Notes from my clanker, checked on 175b92d. Built the branch on Windows 10 (19045) with .NU in PATHEXT and .nu associated with nu 0.117.1, and ran 28 script calls (25 .nu, 3 .vbs) through the branch, through 0.117.1 (this code matches main) and through a build with the suggested line. On Windows, clippy with CI's deny flags is clean and cargo test -p nu-command --lib -- cmd_script_path run_external passes (4 tests). On macOS, cargo fmt --check, typos and clippy with CI's flags are clean. I didn't run clippy on the suggested line.

@fdncred

fdncred commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

I kind of worry about calling wscript failing in ci because if it does it'll post a pop up and hand the entire ci

@iamsiddhesh-dev

Copy link
Copy Markdown
Contributor Author

@fdncred On the WScript worry: in the last run, Windows / root passed and all the .vbs tests ran without hanging. If you'd still rather not have WScript in CI, I can mark them #[ignore] or drop them and keep just the unit test. Your call.

@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Nov 23, 2026
@fdncred
fdncred merged commit d0ab033 into nushell:main Nov 23, 2026
14 checks passed
@fdncred

fdncred commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Thanks

@github-actions github-actions Bot added this to the v0.118.0 milestone Nov 23, 2026
@iamsiddhesh-dev
iamsiddhesh-dev deleted the fix/run-external-forward-slash-script branch November 24, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

./script.nu fails while .\script.nu works with file associations

2 participants