Repository navigation
Closed
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-FixedThe issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtime
Description
Related issue: #4645
run.ps1
Start-Transcript -Path (Join-Path $PSScriptRoot 'transcriptdata.txt')
$InformationPreference = 'SilentlyContinue'
Write-Information 'SilentlyContinue'
$InformationPreference = 'Continue'
Write-Information 'LoudlyContinue'
Stop-TranscriptSteps to reproduce
.\run.ps1Expected behavior
transcriptdata.txt should contains only LoudlyContinue
Actual behavior
transcriptdata.txt contains only SilentlyContinue
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 6.1.0-preview.1
PSEdition Core
GitCommitId v6.1.0-preview.1
OS Microsoft Windows 10.0.16299
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Investigation
The problem is in if/else statement which starts here:
PowerShell/src/System.Management.Automation/engine/MshCommandRuntime.cs
Lines 757 to 758 in 948532a
| if ((record.Tags.Contains("PSHOST") && (!record.Tags.Contains("FORWARDED"))) | |
| || (preference == ActionPreference.Continue)) |
and has a continuation here:
PowerShell/src/System.Management.Automation/engine/MshCommandRuntime.cs
Lines 824 to 828 in 948532a
| else | |
| { | |
| // Only transcribe informational messages here. Transcription of PSHost-targeted messages is done in the InternalUI.Write* methods. | |
| CBhost.InternalUI.TranscribeResult(StringUtil.Format(InternalHostUserInterfaceStrings.InformationFormatString, record.ToString())); | |
| } |
Transcription of Write-Host commands are handled in InternalUI.Write* methods as the comment suggests. These commands are distinguished by "PSHOST" tag.
Transcription of Write-Information commands is supposed to take place in the else statement but code in this statement is being executed only if
(!record.Tags.Contains("PSHOST") || record.Tags.Contains("FORWARDED"))
&&
preference != ActionPreference.Continue)This condition is invalid. Correct condition is:
!record.Tags.Contains("PSHOST")
&&
preference == ActionPreference.Continue)PR pending...
Metadata
Metadata
Assignees
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-FixedThe issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtime
Activity
iSazonov commentedon May 22, 2018
Michael Klement (@mklement0) Could you please comment?
mklement0 commentedon May 22, 2018
Thanks for taking this on, Hubert Bukowski (@hubuk).
It's definitely a step in the right direction, but other quirks remain, so maybe we can expand the scope of your PR.
The following test code contrast the console output of various
Write-Information/Write-Host/Out-Hostcommands with respect to what prints to the console vs. what shows in the transcript (which should be the same):Your current PR commendably fixes the
Write-Informationbehavior in principle, but in the transcript its output is still prefixed withINFO:, unlike in the console.Write-Hostoutput still invariably end up in the transcript - while-InformationAction Ignore/6>$nullworks in the console, it doesn't in the transcript.While fixing the quirks is definitely desirable, we also have to ask ourselves whether user may depend on the old behavior, such as expecting
Write-Informationoutput to be there by default.Steve Lee (@SteveL-MSFT), any thoughts on this and the other issues mentioned in #4645 with respect to backward compatibility?
iSazonov commentedon May 23, 2018
I agree with fixing the Issue too.
For others I'd open new issue for every inconsistency - I believe we get conclusions faster.
hubuk commentedon May 23, 2018
Michael Klement (@mklement0) I made changes to INFO: prefix, but I observe different behavior in
Write-Host 'write-host ignore' -InformationAction Ignorethan you described. It is present in transcript but not in the console.I think that Write-Host should always be visible in both console and transcript regardless of InformationAction and $InformationPreference.
SteveL-MSFT commentedon May 23, 2018
My general view is that
Start-Transcript, by default, is expected to log your inputs and the outputs and should resemble what you would see at the console. Anything more than that should require the use of a parameter or switch. Where behavior changes (breaking changes) are needed to accomplish this, we'll need to determine the impact to the user and decide on a case-by-base basis.mklement0 commentedon May 23, 2018
Hubert Bukowski (@hubuk):
Yes, that is the behavior I was trying to describe.
That applies to
Out-Host, but not toWrite-Host, which is now a bit of a misnomer in that it writes to the information stream, not to the host directly.From what I understand it is by design that in v5+ you can silence
Write-Hostwith-InformationAction Ignore/6>$null(and that you can generally redirect it with6>).In short: My understanding is that
Write-Hostis now an output-by-default companion to the silent-by-defaultWrite-Information(with additional, UI-related features).iSazonov commentedon May 23, 2018
It writes to the informational stream and then to host directly based on tag presence.
mklement0 commentedon May 23, 2018
Ilya (@iSazonov): Yes, but you can suppress
Write-Hostoutput to the host with-InformationAction Ignore/6>$null, whereas the output still shows in the transcript, and that's the problem.iSazonov commentedon May 23, 2018
Agree.
hubuk commentedon May 23, 2018
If
-InformatioAction Ignoreshould suppressWrite-Hostfrom writing to console then-InformationAction SilentlyContinueshould also suppress console output for consistency.But for me it seems more natural that
Write-Hostshould always writes to host. Its interaction with InformationStream can be controlled using InformationAction and InformationPreference variable. If the appearance on the console shall be controlled using these then Write-Information should be used instead. That was my understanding of the differences between these two commands.mklement0 commentedon May 23, 2018
That's not possible, because that would make
Write-Hostsilent by default, given that$InformationPreferencedefaults toSilentlyContinueand, in the absence of an explicit-InformationActionargument, is equivalent to passing-InformationAction SilentlyContinue.For backward compatibility (alone) you don't want
Write-Hostto be silent by default.That's what the name of the cmdlet suggests, and that's how it used to work.
However, as https://github.com/PowerShell/PowerShell-Docs/blob/staging/reference/6/Microsoft.PowerShell.Utility/Write-Information.md states:
(Ignore the fact that this is not the entirely accurate, because the
Ignorevalue passed to-InformationActiondoes affectWrite-Hostand is in effect equivalent to6>$null.)Presumably - and perhaps someone from the team can confirm - this slight repurposing of
Write-Hostsince v5 was to compensate for frequent misuse ofWrite-Hostby cmdlet/function authors, which resulted in callers being unable to capture or suppress its output.By making
Write-Hostwrite to the information stream (number6) instead, it became possible to either suppress or capture its output. (Note that, as stated,Out-Hostindeed still only and invariably prints to the host (and possibly transcript)).hubuk commentedon Jun 16, 2018
Closed via #6917.