You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
redundant escape of " in command run-external #16264
'\"C:/Program Files (x86)/Intel/oneAPI/setvars.bat\"' is not recognized as an internal or external command,
operable program or batch file.
Here you can see, nu escape the " with \, even when the raw string sigil(r#') is used.
And the stupid cmd can only read "C:/Program Files (x86)/Intel/oneAPI/setvars.bat".
So can we avoid this escape somehow??
Currently in Nushell there doesn't seem to be a way of running arbitrary .exe files without forcing the MSVCRT quoting rules on the arguments.
Root Cause
When Nushell (or any other Rust program in general) wants to run another program, it uses std::process::Command. Command has a concept of multiple arguments. Linux kernel, when you run a program, has a concept of multiple arguments. Windows does not - there is just one argument to running a program (called a "command line"), and it's up to the target program to decide how it wants to parse that.
There is one convention in Windows world for how to pack multiple args into a single string - the MSVCRT one. This is what Command is encoding on Windows by default and that is where those uncalled for \ come from. Nushell trusts Rust to take care of args, and Rust devs decided that MSVCRT is the sensible default on Windows, even if there does not exist a rule saying that all Windows binaries have to follow MSVCRT, and cmd.exe doesn't.
Solutions
Universal escape hatch
Add a --rawargs (bikeshed) flag to run-external that would disable std::process::Command's MSVCRT behavior - Rust already supports this escape hatch via raw_arg.
This will allow correct usage of any Windows binary that does not conform to MSVCRT and will solve the problem universally, beyond just cmd.exe. The user would have to understand the target program's argument encoding convention on their own and construct the string with that in mind.
The downside is that people would still trip over direct calls to cmd.exe not knowing the right way to call is run-external --rawargs.
The downsides are still that people wouldn't know to run cmdexe instead of cmd.exe, and that it doesn't cover other Windows programs that don't conform to MSVCRT, so it's less useful than the universal solution.
Detect cmd.exe being run
That's what PowerShell is doing: detecting that it's going to spawn a cmd.exe and disables MSVCRT encoding for its args.
The downside is false positives - if you disable MSVCRT encoding and the target program is not a Windows cmd.exe and just happens to have the same file name, you might get very nasty bugs and even security vulnerabilities. But, this might be mitigated by verifying the target binary's certificate, i.e. what company signed it. If it's Microsoft, chances
are good it's a Windows cmd.exe.
Proclaim non-MSVCRT binaries support as a non-goal
You can just say Nushell doesn't want to support non-MSVCRT external command arguments by design and point to workarounds such as placing your cmd.exe code into a dedicated .bat file and running that file from Nushell, since Rust already handles that case.
Security concerns
Isn't an internal cmdexe command an "eval" kind of thing?
Only in the sense that you're able to run an external program that executes input code.
You can already do that in Nushell with any other program:
Powershell:
~> run-external powershell.exe '-NoProfile' '-Command' r#'Write-Host 'hi'; Get-Date'#
hi
Friday, January 16, 2026 23:49:30
Bash:
~> run-external c:\msys64\usr\bin\bash.exe '-lc' r#'echo hi ; date'#
hi
Fri, Jan 16, 2026 23:51:02
Nushell:
~> run-external nu.exe '-c' r#'print 'hi' ; date now'#
hi
Fri, 16 Jan 2026 23:51:59 +0100 (now)
Cmd.exe:
Not reliably possible because of Nu's limitation, but still:
~> run-external cmd.exe '/d' '/c' 'echo hi & date'
hi
The current date is: 2026-01-16
Enter the new date: (yy-mm-dd)
So, if you interpret "eval" as being able to run dynamically-constructed code, then this is already a feature of Nushell no matter what, even of Nushell scripts, with all of the dangers of user injected code that it brings. The injection issue is A) unsolvable in principle as long you allow running external commands, and B) orthogonal to the issue of not currently being able to run cmd.exe correctly.
Activity
fdncred commentedon Jul 26, 2025
Have you tried using backticks instead of raw strings? Another thing you can try is using string interpolation or using env vars like I did below.
This is something I wrong a while back to do something similar.
gravitional commentedon Jul 26, 2025
Backticks give the same result.
But I will try your codes, thanks a lot !
gravitional commentedon Jul 26, 2025
Furthermore, if one use powershell, in the way below,
it just works as one would expected,
It is intuitive.
motgenror commentedon Jan 17, 2026
Thoughts on this:
Problem
Currently in Nushell there doesn't seem to be a way of running arbitrary
.exefiles without forcing the MSVCRT quoting rules on the arguments.Root Cause
When Nushell (or any other Rust program in general) wants to run another program, it uses
std::process::Command.Commandhas a concept of multiple arguments. Linux kernel, when you run a program, has a concept of multiple arguments. Windows does not - there is just one argument to running a program (called a "command line"), and it's up to the target program to decide how it wants to parse that.There is one convention in Windows world for how to pack multiple args into a single string - the MSVCRT one. This is what
Commandis encoding on Windows by default and that is where those uncalled for\come from. Nushell trusts Rust to take care of args, and Rust devs decided that MSVCRT is the sensible default on Windows, even if there does not exist a rule saying that all Windows binaries have to follow MSVCRT, andcmd.exedoesn't.Solutions
Universal escape hatch
Add a
--rawargs(bikeshed) flag torun-externalthat would disablestd::process::Command's MSVCRT behavior - Rust already supports this escape hatch via raw_arg.This will allow correct usage of any Windows binary that does not conform to MSVCRT and will solve the problem universally, beyond just
cmd.exe. The user would have to understand the target program's argument encoding convention on their own and construct the string with that in mind.The downside is that people would still trip over direct calls to
cmd.exenot knowing the right way to call isrun-external --rawargs.Example:
Cmdexe-specific escape hatch
Add an internal command that runs
cmd.exe /cfor you with MSVCRT encoding turned off, let's call itcmdexe(bikeshed).Example:
The downsides are still that people wouldn't know to run
cmdexeinstead ofcmd.exe, and that it doesn't cover other Windows programs that don't conform to MSVCRT, so it's less useful than the universal solution.Detect cmd.exe being run
That's what PowerShell is doing: detecting that it's going to spawn a
cmd.exeand disables MSVCRT encoding for its args.Examples:
The downside is false positives - if you disable MSVCRT encoding and the target program is not a Windows
cmd.exeand just happens to have the same file name, you might get very nasty bugs and even security vulnerabilities. But, this might be mitigated by verifying the target binary's certificate, i.e. what company signed it. If it's Microsoft, chancesare good it's a Windows
cmd.exe.Proclaim non-MSVCRT binaries support as a non-goal
You can just say Nushell doesn't want to support non-MSVCRT external command arguments by design and point to workarounds such as placing your cmd.exe code into a dedicated
.batfile and running that file from Nushell, since Rust already handles that case.Security concerns
Isn't an internal
cmdexecommand an "eval" kind of thing?Only in the sense that you're able to run an external program that executes input code.
You can already do that in Nushell with any other program:
Powershell:
Bash:
Nushell:
Cmd.exe:
Not reliably possible because of Nu's limitation, but still:
So, if you interpret "eval" as being able to run dynamically-constructed code, then this is already a feature of Nushell no matter what, even of Nushell scripts, with all of the dangers of user injected code that it brings. The injection issue is A) unsolvable in principle as long you allow running external commands, and B) orthogonal to the issue of not currently being able to run
cmd.execorrectly.fdncred commentedon Jan 17, 2026
Nice write up @motgenror. I think I'm personally leaning towards
--raw-args. I've asked the core-team to chime in. They may or may not reply.I could also live with
cmdexenamedwinrunand being a windows-only command, but I don't really like os-only commands that much.