-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add exec cmdlet for bash compatibility
#16462
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
Conversation
|
I wonder MSFT team denies its own policy of not increasing Engine :-) Why don't put the short function in AzCLI with a helper module to collect a feedback. Then we could put the function in Utility module for 7.3. |
|
@iSazonov it's not just AzCLI, that's just the most recent example. I've hit this myself a few times and it's really hard to figure out what's going on as an end user as the native command doesn't expect |
@SteveL-MSFT I see the point and I approve the intention but I'm afraid we may fall back into a long commit series of adaptations, especially if there is an intention to backport. |
|
What do we know popular scripts using the exec which we could test with the solution? I see only two references in the related issue. |
|
Why not do the real system call
|
We call |
|
I'm going to re-work this PR so that |
exec is a built-in function See: PowerShell/PowerShell#16462
exec function for bash compatibilityexec cmdlet for bash compatibility
src/System.Management.Automation/engine/Modules/SwitchProcessCommand.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/Modules/SwitchProcessCommand.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/Modules/SwitchProcessCommand.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/Modules/SwitchProcessCommand.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/Modules/SwitchProcessCommand.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/Modules/SwitchProcessCommand.cs
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Core/Exec.Tests.ps1
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/Modules/SwitchProcessCommand.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/Modules/SwitchProcessCommand.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/resources/CommandBaseStrings.resx
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Core/Exec.Tests.ps1
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Core/Exec.Tests.ps1
Outdated
Show resolved
Hide resolved
|
It occurs to me that there might be some insight that the dotnet folks may have on this. I'm thinking especially of open file handles (which are preserved through the |
|
Also, since this is a PowerShell view of |
|
The actual implementation should be in our native library and we should be calling the API from that library rather than directly having the system call. |
|
We also need to figure out what to do about the |
|
@JamesWTruher over time, we probably want to get rid of our native library and move them all to P/Invoke or .NET API calls. This will make it easier for us to support new architectures and also support MSIL builds. As for the separate I've also asked .NET team to review this. |
They introduced new GeneratedDllImport attribute and it would be great if they reviewed PowerShell Native repo too - can we rid of the PowerShell Native now (after moving to .Net 7) or no? |
|
@iSazonov I thought I had opened an issue previously on moving away from |
|
with regard to eliminating the native library, there may be difficulties with some of the APIs. I know when I did the UnixStat work I needed to handle all the platform differences in returning the stat structure. The stat structure is different on Mac, Linux, and ARM - this would likely be problematic - i solved it in the native library by returning a CommonStat structure which smoothed over the rough edges of these differences. |
It is great request for .Net team. I see their dll import generator works today for simple types but structs are under question. |
src/System.Management.Automation/engine/Modules/SwitchProcessCommand.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/resources/CommandBaseStrings.resx
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/Modules/SwitchProcessCommand.cs
Outdated
Show resolved
Hide resolved
…ommand.cs Co-authored-by: Sean Wheeler <sean.wheeler@microsoft.com>
…resx Co-authored-by: Ilya <darpa@yandex.ru>
Co-authored-by: Ilya <darpa@yandex.ru>
…ommand.cs Co-authored-by: Dongbo Wang <dongbow@microsoft.com>
…resx Co-authored-by: Dongbo Wang <dongbow@microsoft.com>
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
daxian-dbw
left a comment
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.
LGTM
|
🎉 Handy links: |
|
@PowerShell/powershell-maintainers Let's give this some bake time to verify that it is stable. |
|
I have seen customers that implement exec as a cmdlet which this behavior could break. The maintainers are inclined not to backport this unless we have a compelling argument to backport to the last LTS. |
|
@PowerShell/powershell-committee reviewed this. Given that this is an experimental feature in 7.3 and the risk of impact of an existing |
PR Summary
Some native unix command will shell out to run something (like
ssh) and uses the bash built-inexecto spawn a new process that replaces the current one. This fails when PowerShell is the default shell asexecis not a valid command.This is affecting some known scripts like
copy-ssh-idor some subcommands of AzCLI.Since
Replaceis not a valid verb, I decided to useSwitch. Also, the other "Process" cmdlets are in the ManagementModule, but this is not related to those cmdlets and is really a Core cmdlet expected to be part of a Unix shell.This PR adds a new
Switch-Processcmdlet aliased toexecthat callsexecv()function to provide similar behavior as POSIX shells. This is not intended to have parity with theexecbuilt-in function in POSIX shells (like how file descriptors are handled), but should cover most cases. This cmdlet only shows up for non-Windows systems.We should consider backporting to 7.2 (as LTS release) for this reason, but should wait on sufficient user feedback in 7.3.
This may conflict with a user defined function called
execon non-Windows systems, but this seems necessary and uncommon. @PowerShell/powershell-committee had previously decided this was acceptable.PR Context
Fix #4691
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.PSExecexecfunction MicrosoftDocs/PowerShell-Docs#8349(which runs in a different PS Host).