New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a Windows mode for native commands that allows some commands to use legacy argument passing #15408
Conversation
2fe31da
to
8ed04ee
Compare
a791375
to
3ca1aff
Compare
src/System.Management.Automation/engine/NativeCommandProcessor.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/NativeCommandProcessor.cs
Outdated
Show resolved
Hide resolved
test/powershell/Language/Scripting/NativeExecution/NativeCommandArguments.Tests.ps1
Show resolved
Hide resolved
I believe this PR addresses part of #15143 |
135cab4
to
778e8e0
Compare
@SteveL-MSFT - I think I've addressed your issues, please let me know |
@JamesWTruher one comment was not addressed |
src/System.Management.Automation/engine/NativeCommandProcessor.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/NativeCommandProcessor.cs
Outdated
Show resolved
Hide resolved
return false; | ||
} | ||
|
||
string commandPath = filePath.ToLowerInvariant(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to allocate. We can do if (filePath.EndsWith(exception, StringComparison.OrdinalIgnoreVase))
in line 1302.
src/System.Management.Automation/engine/NativeCommandProcessor.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/NativeCommandProcessor.cs
Outdated
Show resolved
Hide resolved
I'm not sure this is working completely for cmd.exe - ie excluding cmd.exe. preview.6 breaks the
This is basically Lee Holmes old function that we have implemented in PSCX: function Invoke-BatchFile
{
param([string]$Path, [string]$Parameters)
$tempFile = [IO.Path]::GetTempFileName()
## Store the output of cmd.exe. We also ask cmd.exe to output
## the environment table after the batch file completes
cmd.exe /c " `"$Path`" $Parameters && set " > $tempFile
...
} Reverting to |
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
fc7da11
to
350c8b0
Compare
@rkeithhill wrt the pscx issue that you mentioned. Have you tried running this branch against your scenario? This PR is supposed to automatically put the arg passing into legacy mode for cmd.exe invocations, so it should be fine (but I would really like confirmation on that). I've added validation for that very scenario, but I might have missed something. |
@rkeithhill - excellent - the default setting for windows will be "Windows", which is the hybrid model where certain commands will run as Legacy while others will use "Standard". This should hopefully be better and allow the wacky parsing that happens for batch files, but enable more modern apps to use the new style. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at Rob's suggestion
Reassigning to @rjmholt as @daxian-dbw is taking time off right now |
src/System.Management.Automation/engine/NativeCommandParameterBinder.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/NativeCommandProcessor.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/NativeCommandProcessor.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/NativeCommandProcessor.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/NativeCommandProcessor.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/NativeCommandProcessor.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/NativeCommandProcessor.cs
Outdated
Show resolved
Hide resolved
test/powershell/Language/Scripting/NativeExecution/NativeCommandArguments.Tests.ps1
Outdated
Show resolved
Hide resolved
test/powershell/Language/Scripting/NativeExecution/NativeCommandArguments.Tests.ps1
Outdated
Show resolved
Hide resolved
test/powershell/Language/Scripting/NativeExecution/NativeCommandArguments.Tests.ps1
Outdated
Show resolved
Hide resolved
Opened JamesWTruher#15 to add remaining suggested changes |
Make suggested changes to NativeArgPassing PR
/azp run |
Azure Pipelines successfully started running 6 pipeline(s). |
…se legacy argument passing (PowerShell#15408)
🎉 Handy links: |
PR Summary
This PR targets a consistent default behavior between PowerShell 5 and PowerShell 7 on Windows for some executables and file types. The behavior is now update to use the legacy behavior for the following files:
This list is table driven, and can be easily altered. I have started with this list as I am familiar with real world issues with them.
The PSNativeArgumentPassing preference value has been expanded to include the new value
Windows
. When the preference variable is set toWindows
the above table will be in effect, meaning that invocations of those files will automatically use theLegacy
style argument passing. If the PSNativeArgumentPassing is set to eitherLegacy
orStandard
, then the additional checks will not take place.The default behavior is now also platform specific. On Windows platforms, the default setting will be
Windows
and non-Windows platforms will beStandard
.PR Context
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).