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 pwshw
for console-less PowerShell on Windows
#10962
Conversation
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.
🎉
@SteveL-MSFT Re PR description - The PR doesn't fix initial request in #3028, it is implement another case. |
@alexbuzzbee pwshw is only one option from many in the complex topic. My PR seems add more flexibility and allow to experiment with console, non-console, pseudo-console and GUI modes, and also fix |
@iSazonov I don't think the two are mutually exclusive |
@SteveL-MSFT I updated a description in my PR to clarify my vision. |
@SteveL-MSFT Some packaging changes are needed:
|
@SteveL-MSFT Could you please elaborate more about the expectation of |
@daxian-dbw updated description |
No tests running for pwshw. |
@iSazonov what do you mean? The additional test was run: https://powershell.visualstudio.com/PowerShell/_build/results?buildId=37337&view=logs&jobId=65e467a7-433b-584d-c8f4-72fcd5732f9d&taskId=6a14d04a-9a6d-5c41-f839-531117eeb032&lineStart=857&lineEnd=858&colStart=1&colEnd=1 I don't think there's a need to rerun all tests with pwshw.exe, it's a compilation flag. |
Why not if we expect that some features will do not work? Are you sure that all feature which must works really works? (In my PR (although another scenario) 66 tests failed in one job) |
@iSazonov I'll see about running the tests manually, anything expecting a console won't work as that's the design of being consoleless. Otherwise, pwshw.exe doesn't do much by itself and still relies on ConsoleHost.dll. |
@adityapatwardhan mscodehub build succeeded, will fix merge conflict after getting pwshw test results |
@SteveL-MSFT I tried the artifacts out of the mscodehub build. Does not seem to work :( |
@adityapatwardhan |
Ok, definitely a problem here. Write-Host immediately fails. Need to have it handle the case there is no host. |
In my PR I follow these cases: (1) AllocConsole() for normal pwsh.exe scenario, (2) AttachConsole(-1) to attach to parent process console in Hidden scenario. This doesn't pass all tests on CIs, I still don't investigate what tests must pass but failed. |
Had to use Invoke-Pester since |
…eterParser.cs Co-Authored-By: Ilya <darpa@yandex.ru>
Co-Authored-By: Ilya <darpa@yandex.ru>
- Add pwshw tests to daily - Update copyright notice in pwshw.tests.ps1
pwshw
for console-less PowerShell on Windows
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.
I have still concerns about skipped tests. I'd expect that we add new positive test for pwshw if we skip a test for pwsh. But I did not review this in depth.
src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Core/Out-Host.Tests.ps1
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1
Outdated
Show resolved
Hide resolved
FYI - #3028 (comment) talks about the console team's work to address this particulat deficiency. It might take some time to come to all Windows versions, but |
Closing this for now and waiting for Windows solution. |
@SteveL-MSFT Even if we get this feature in Windows API in future we could merge 90% of this PR today and save your efforts. |
PR Summary
.NET Core 3.0 supports building WinExe type which doesn't bind to console host. This means that pwshw.exe launches like any GUI app (think notepad) and stdin/stdout/stderr isn't bound to pwshw.exe from wherever it is started. This is conceptually equivalent to the old
wscript.exe
andcscript.exe
tools.Build script updated to also build a new
powershell-win-core-w
project as we still need the console pwsh.exe built. The resulting pwshw.exe and other necessary files are copied to the pwsh.exe folder.This is exposed as an experimental feature although it can't be disabled as it's a binary file.
pwshw
is never attached a console, so-OutputLog
is added to the host to write output to a file making it easier to trouble issues.pwshw
is always non-interactive even if the-interactive
switch is used. ConsoleHost UserInterfaces updated to write to OutputLog if set. Code paths that try to access ActiveScreenBuffer have try...catch to fail silently when there is no console. Tests updated to account for being run within pwshw where necessary. Tests using pwsh and expecting console output is left as-is. CI is updated to run all CI and Other tests both elevated and unelevated under this new host on Windows.PR Context
Fix #3028
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.PSConsoleLessHost