Skip to content
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

Closed
wants to merge 32 commits into from

Conversation

SteveL-MSFT
Copy link
Member

@SteveL-MSFT SteveL-MSFT commented Nov 1, 2019

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 and cscript.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.

NOTE: scripts that call console APIs will fail as those APIs will throw that there is no console

PR Context

Fix #3028

PR Checklist

Copy link
Contributor

@RDIL RDIL left a comment

Choose a reason for hiding this comment

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

🎉

@iSazonov
Copy link
Collaborator

iSazonov commented Nov 1, 2019

@SteveL-MSFT Re PR description - The PR doesn't fix initial request in #3028, it is implement another case.
To address #3028 I created #10965. I think we could implement pwshw in #10965 in the same way as we did an alias for preview-pwsh.

@ghost
Copy link

ghost commented Nov 1, 2019

@iSazonov The consensus in the discussion for #3028 is that the solution is to create a pwshw variant instead of continuing to use -WindowStyle Hidden, and this PR does that fairly cleanly.

@iSazonov
Copy link
Collaborator

iSazonov commented Nov 1, 2019

@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 -WindowStyle Hidden scenario.

@SteveL-MSFT
Copy link
Member Author

@iSazonov I don't think the two are mutually exclusive

@iSazonov
Copy link
Collaborator

iSazonov commented Nov 1, 2019

@SteveL-MSFT I updated a description in my PR to clarify my vision.

@adityapatwardhan
Copy link
Member

adityapatwardhan commented Nov 1, 2019

@SteveL-MSFT Some packaging changes are needed:

  1. Include pwshw for signing:
    <file src="__INPATHROOT__\pwsh.exe" signType="AuthenticodeFormer" dest="__OUTPATHROOT__\pwsh.exe" />
  2. WXS file needs to be updated
  3. Maybe some changes are needed in https://github.com/PowerShell/PowerShell/blob/master/tools/packaging/packaging.psm1
  4. Once these changes are done, please scheduled a full signed build on your branch in Azure DevOps.
GitHub
PowerShell for every system! Contribute to PowerShell/PowerShell development by creating an account on GitHub.

@daxian-dbw
Copy link
Member

@SteveL-MSFT Could you please elaborate more about the expectation of pwshw? Like what will not work (will all console related operations not work?)

@SteveL-MSFT
Copy link
Member Author

@daxian-dbw updated description

@iSazonov
Copy link
Collaborator

iSazonov commented Nov 1, 2019

No tests running for pwshw.

@SteveL-MSFT
Copy link
Member Author

@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.

@iSazonov
Copy link
Collaborator

iSazonov commented Nov 1, 2019

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)

@SteveL-MSFT
Copy link
Member Author

@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.

@SteveL-MSFT
Copy link
Member Author

SteveL-MSFT commented Nov 1, 2019

@adityapatwardhan mscodehub build succeeded, will fix merge conflict after getting pwshw test results

@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Nov 1, 2019
@adityapatwardhan
Copy link
Member

@SteveL-MSFT I tried the artifacts out of the mscodehub build. Does not seem to work :(

image

@SteveL-MSFT
Copy link
Member Author

SteveL-MSFT commented Nov 1, 2019

@adityapatwardhan pwshw.exe is a Windows App, so it's not associated with the console. You'll need to have it redirect to a file within your command: pwshw -nop -c '$PSVersionTable > ~/out.txt'

@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Nov 1, 2019
@SteveL-MSFT SteveL-MSFT changed the title Add pwshw for console-less PowerShell on Windows WIP: Add pwshw for console-less PowerShell on Windows Nov 1, 2019
@SteveL-MSFT
Copy link
Member Author

Ok, definitely a problem here. Write-Host immediately fails. Need to have it handle the case there is no host.

@iSazonov
Copy link
Collaborator

iSazonov commented Nov 2, 2019

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.

@SteveL-MSFT
Copy link
Member Author

Tests completed in 3676.82s
Tests Passed: 7644,
Failed: 127,
Skipped: 335,
Pending: 106,
Inconclusive: 2

Had to use Invoke-Pester since Start-PSPester expects pwsh.exe. Will have to look through the failures.

 - Add pwshw tests to daily
 - Update copyright notice in pwshw.tests.ps1
@SteveL-MSFT SteveL-MSFT changed the title WIP: Add pwshw for console-less PowerShell on Windows Add pwshw for console-less PowerShell on Windows Aug 14, 2020
Copy link
Collaborator

@iSazonov iSazonov left a 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.

@DHowett
Copy link

DHowett commented Aug 18, 2020

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 pwshw is a permanent fixture you may need to support forever if you commit to it. 😄

@SteveL-MSFT
Copy link
Member Author

Closing this for now and waiting for Windows solution.

@iSazonov
Copy link
Collaborator

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-Experimental Indicates that a PR should be marked as an Experimental Feature in the Change Log Experimental Experimental Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Powershell -WindowStyle Hidden still shows a window briefly
10 participants