GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add `pwshw` for console-less PowerShell on Windows by SteveL-MSFT · Pull Request #10962 · PowerShell/PowerShell

Conversation

@SteveL-MSFT

@SteveL-MSFT Steve Lee (SteveL-MSFT) commented Nov 1, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Make sure all .h, .cpp, .cs, .ps1 and .psm1 files have the correct copyright header
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: or [ WIP ] to the beginning of the title (the WIP bot will keep its status check at Pending while the prefix is present) and remove the prefix when the PR is ready.
  • Breaking changes
    • None
    • OR
    • Experimental feature(s) needed
      • Experimental feature name(s): PSConsoleLessHost
  • User-facing changes
    • Not Applicable
    • OR
    • Documentation needed
      • Issue filed: Doc new pwshw.exe for PS7 MicrosoftDocs/PowerShell-Docs#5039
  • Testing - New and feature
    • N/A or can only be tested interactively
    • OR
    • Make sure you've added a new test if existing tests do not effectively test the code changed
  • Tooling
    • I have considered the user experience from a tooling perspective and don't believe tooling will be impacted.
    • OR
    • I have considered the user experience from a tooling perspective and enumerated concerns in the summary. This may include:
      • Impact on PowerShell Editor Services which is used in the PowerShell extension for VSCode (which runs in a different PS Host).
      • Impact on Completions (both in the console and in editors) - one of PowerShell's most powerful features.
      • Impact on PSScriptAnalyzer (which provides linting & formatting in the editor extensions).
      • Impact on EditorSyntax (which provides syntax highlighting with in VSCode, GitHub, and many other editors).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Jaykul, jpogran, DoCode, rokumaru, ttimasdf, and AfroThundr3007730 reacted with thumbs up emoji kvprasoon, Jaykul, jpogran, DoCode, and gjones358 reacted with hooray emoji
All reactions
  • 👍 6 reactions
  • 🎉 5 reactions
@SteveL-MSFT
Steve Lee (SteveL-MSFT) requested a review from Aditya Patwardhan (adityapatwardhan) November 1, 2019 04:29
@SteveL-MSFT
Steve Lee (SteveL-MSFT) requested review from Travis Plunk (TravisEz13), Andrew (anmenaga) and Dongbo Wang (daxian-dbw) as code owners November 1, 2019 04:29
@SteveL-MSFT Steve Lee (SteveL-MSFT) assigned Aditya Patwardhan (adityapatwardhan) Nov 1, 2019
@SteveL-MSFT Steve Lee (SteveL-MSFT) mentioned this pull request Nov 1, 2019
Doc new pwshw.exe for PS7 MicrosoftDocs/PowerShell-Docs#5039
Closed
1 of 10 tasks
RDIL
Reece Dunham (RDIL) approved these changes Nov 1, 2019
View reviewed changes

@RDIL Reece Dunham (RDIL) left a comment

Copy link
Copy Markdown
Contributor

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.

🎉

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@iSazonov

Ilya (iSazonov) commented Nov 1, 2019

Copy link
Copy Markdown
Collaborator

Steve Lee (@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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ghost

Deleted user (ghost) commented Nov 1, 2019

Copy link
Copy Markdown

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

doctordns reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw Dongbo Wang (daxian-dbw) mentioned this pull request Nov 1, 2019
Resolve -WindowStyle Hidden console flashing #10965
Closed
14 tasks
@iSazonov

Ilya (iSazonov) commented Nov 1, 2019

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Nov 1, 2019

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Nov 1, 2019

Copy link
Copy Markdown
Collaborator

Steve Lee (@SteveL-MSFT) I updated a description in my PR to clarify my vision.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adityapatwardhan

Aditya Patwardhan (adityapatwardhan) commented Nov 1, 2019 •
edited by unfurl-links Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Steve Lee (@SteveL-MSFT) Some packaging changes are needed:

  1. Include pwshw for signing:

    PowerShell/tools/releaseBuild/signing.xml

    Line 25 in 417cbd7

    <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/PowerShell
PowerShell for every system! Contribute to PowerShell/PowerShell development by creating an account on GitHub.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw

Dongbo Wang (daxian-dbw) commented Nov 1, 2019

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Nov 1, 2019

Copy link
Copy Markdown
Member Author

Dongbo Wang (@daxian-dbw) updated description

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Nov 1, 2019

Copy link
Copy Markdown
Collaborator

No tests running for pwshw.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Nov 1, 2019

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Nov 1, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

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)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Nov 1, 2019

Copy link
Copy Markdown
Member Author

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

iSazonov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Nov 1, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

Aditya Patwardhan (@adityapatwardhan) mscodehub build succeeded, will fix merge conflict after getting pwshw test results

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

adityapatwardhan
Aditya Patwardhan (adityapatwardhan) requested changes Nov 1, 2019
View reviewed changes
Comment thread tools/releaseBuild/signing.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

@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

Aditya Patwardhan (adityapatwardhan) commented Nov 1, 2019

Copy link
Copy Markdown
Member

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

image

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Nov 1, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

Aditya Patwardhan (@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'

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@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 Steve Lee (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

Steve Lee (SteveL-MSFT) commented Nov 1, 2019

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Nov 2, 2019

Copy link
Copy Markdown
Collaborator

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Nov 2, 2019

Copy link
Copy Markdown
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.

iSazonov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Steve Lee (SteveL-MSFT) and others added 11 commits August 12, 2020 10:15
@SteveL-MSFT
fix transcription test
14d77e9
@SteveL-MSFT
fix Codacy issue
b7b8561
@SteveL-MSFT
remove unused member
fbd5468
@SteveL-MSFT
enable unelevated pwshw tests
f558536
@SteveL-MSFT
fix validation of ci test purpose
d796f6b
@SteveL-MSFT
handle not being able to create the outputlog
2ecaf02
@SteveL-MSFT
enable CI tests for pwshw
b5a733f
@SteveL-MSFT
fix transcript tests
4d48f7c
@SteveL-MSFT
expose as Experimental Feature, fix writing to outputlog, add tests
ada4330
@SteveL-MSFT @iSazonov
Update src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParam…
a6e88cf
…eterParser.cs

Co-Authored-By: Ilya <[email protected]>
@SteveL-MSFT @iSazonov
Update src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
f651490
Co-Authored-By: Ilya <[email protected]>
@SteveL-MSFT
Steve Lee (SteveL-MSFT) force-pushed the pwshw branch from 90cb59e to fd0a4f4 Compare August 12, 2020 17:17
@SteveL-MSFT
address Ilya's feedback
957f516
@SteveL-MSFT
Steve Lee (SteveL-MSFT) force-pushed the pwshw branch from fd0a4f4 to 957f516 Compare August 12, 2020 17:24
Steve Lee (SteveL-MSFT) added 4 commits August 12, 2020 10:27
@SteveL-MSFT
fix codefactor issue making OutputLog nullable
a50f869
@SteveL-MSFT
update Files.wxs
15799e2
@SteveL-MSFT
define pwshw results filepath
20989b9
@SteveL-MSFT
update packaging files
c0dd6fd
TravisEz13
Travis Plunk (TravisEz13) reviewed Aug 14, 2020
View reviewed changes
Comment thread test/powershell/Host/Pwshw.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

TravisEz13
Travis Plunk (TravisEz13) reviewed Aug 14, 2020
View reviewed changes
Comment thread .vsts-ci/windows.yml Resolved

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT
address Travis' feedback
3cb8e35
 - Add pwshw tests to daily
 - Update copyright notice in pwshw.tests.ps1
@SteveL-MSFT Steve Lee (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
iSazonov
Ilya (iSazonov) reviewed Aug 15, 2020
View reviewed changes

@iSazonov Ilya (iSazonov) left a comment

Copy link
Copy Markdown
Collaborator

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/powershell/Modules/Microsoft.PowerShell.Core/Out-Host.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/powershell/Modules/Microsoft.PowerShell.Utility/Send-MailMessage.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Date.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/powershell/engine/Remoting/ImplicitRemotingBatching.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Steve Lee (SteveL-MSFT) added 2 commits August 18, 2020 14:00
@SteveL-MSFT
address Ilya's feedback
2ec5013
@SteveL-MSFT
add xunit tests
558b26c
@DHowett

Dustin L. Howett (DHowett) commented Aug 18, 2020

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Aug 19, 2020

Copy link
Copy Markdown
Member Author

Closing this for now and waiting for Windows solution.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT Steve Lee (SteveL-MSFT) closed this Aug 19, 2020
@iSazonov

Ilya (iSazonov) commented Aug 19, 2020

Copy link
Copy Markdown
Collaborator

Steve Lee (@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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SufficientDaikon Ahmed Taha (SufficientDaikon) mentioned this pull request Mar 28, 2026
Fix -WindowStyle Hidden console window flash #27111
Open
8 of 12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@TravisEz13 Travis Plunk (TravisEz13) TravisEz13 left review comments
@iSazonov Ilya (iSazonov) iSazonov left review comments
@adityapatwardhan Aditya Patwardhan (adityapatwardhan) adityapatwardhan requested changes
@anmenaga Andrew (anmenaga) Awaiting requested review from anmenaga
@daxian-dbw Dongbo Wang (daxian-dbw) Awaiting requested review from daxian-dbw
@JamesWTruher James Truher (JamesWTruher) Awaiting requested review from JamesWTruher
+2 more reviewers
@PoshChan PoshChan-Bot (PoshChan) PoshChan left review comments
@RDIL Reece Dunham (RDIL) RDIL approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@adityapatwardhan Aditya Patwardhan (adityapatwardhan)

Labels

CL-Experimental Indicates that a PR should be marked as an Experimental Feature in the Change Log Experimental Experimental Feature

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Powershell -WindowStyle Hidden still shows a window briefly

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@SteveL-MSFT @iSazonov @adityapatwardhan @daxian-dbw @vexx32 @TylerLeonhardt @TravisEz13 @DHowett @RDIL @PoshChan
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.