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
Start/Stop-Transcript does not capture everything written to the console #10994
Comments
|
TLDR:
I’m not sure this is a bug, per se, but a subtle interaction between the script and how transcription works with our pipelines. I will agree that it is in no way intuitive. One of the things that happen when you emit objects is that the formatting of those objects gets handled by out-default, but after the script has completed and since transcription has stopped, that output doesn’t get transcribed. Strings are handled differently, they’re sometimes short-circuited through formatting (but sometimes not). The combination of write-host (which makes an immediate write), write-object (which may get short-circuited through formatting), and output of a makes this pretty hard to reason about what’s going to happen. However, there may be a way that you may want to try (See “A POSSIBLE WAY” below). Even more details: Here are a couple of variations on the theme: Variation 1 – your scenario, with the output of a structured object at the end of all of the other operations. PS> cat s2.ps1
remove-item s2 -ea ignore
start-transcript s2 -usemin
write-host "1"
write-output "2"
get-location
write-host "4"
write-output "5"
stop-transcript
PS> ./s2.ps1
Transcript started, output file is s2
1
2
4
Path
----
/Users/jimtru/src/projects/transcript
5
Transcript stopped, output file is /Users/jimtru/src/projects/transcript/s2This one is really confusing, but explainable (but perhaps not satisfying). ‘Write-Host 4’ is visible before Since transcription is turned off before the script exits, it’s not rendered in the transcript, because the objects were sent to the next consumer in the pipeline (in this case, it’s out-default which is what the engine does automatically). The tricky bit is that strings are also somewhat hot-rodded in our formatting, so the first **********************
PowerShell transcript start
Start time: 20191106114858
**********************
Transcript started, output file is s2
1
2
4
**********************
PowerShell transcript end
End time: 20191106114858
**********************Variation 2 – move the object emission to the beginning start-transcript s3 -usemin
get-location
write-host "1"
write-output "2"
write-host "4"
write-output "5"
stop-transcriptWe can see that the PS> ./s3.ps1
Transcript started, output file is s3
1
4
Path
----
/Users/jimtru/src/projects/transcript
2
5
Transcript stopped, output file is /Users/jimtru/src/projects/transcript/s3
PS> cat s3
**********************
PowerShell transcript start
Start time: 20191106115142
**********************
Transcript started, output file is s3
1
4
**********************
PowerShell transcript end
End time: 20191106115142
**********************Variation 3 – object emission at the end: PS> cat s4.ps1
start-transcript s4 -usemin
write-host "1"
write-output "2"
write-host "4"
write-output "5"
get-location
stop-transcriptHere’s the execution flow PS> ./s4.ps1
Transcript started, output file is s4
1
2
4
5
Path
----
/Users/jimtru/src/projects/transcript
Transcript stopped, output file is /Users/jimtru/src/projects/transcript/s4And the content of the transcript **********************
PowerShell transcript start
Start time: 20191106115255
**********************
Transcript started, output file is s4
1
2
4
5
**********************
PowerShell transcript end
End time: 20191106115255
**********************A Possible WayLastly, here’s a slight variation on the original, but now everything will be in the transcript. I’ve taken the code of interest and am calling the formatter forcefully via out-default. You’ll notice that the last Write-Host call is still out of order, that’s because of the short-circuiting of write-host which is a direct call into the host and does not go into the output stream. start-transcript s5 -usemin
.{
write-host "1"
write-output "2"
get-location
write-host "4"
write-output "5"
} | out-default
stop-transcriptHere’s the execution, followed by the transcript PS> ./s5.ps1
Transcript started, output file is s5
1
2
4
Path
----
/Users/jimtru/src/projects/transcript
5
Transcript stopped, output file is /Users/jimtru/src/projects/transcript/s5
PS> cat s5
**********************
PowerShell transcript start
Start time: 20191106115701
**********************
Transcript started, output file is s5
1
2
4
Path
----
/Users/jimtru/src/projects/transcript
5
**********************
PowerShell transcript end
End time: 20191106115701
********************** |
|
I suggest adding a new option. Allows it to output color documents |
|
@JamesWTruher Thank you for the detailed reply. Out-Default works great! I ended up using the -Transcript flag so that the objects are still passed forward on the pipeline. @he852100 I'll second this. Color in transcripts would be awesome. |
|
My one question to that is always going to be -- how? PS works with text files, not formatted documents. The next step up would perhaps be Markdown, which would be messier to read in the console, and still doesn't natively support color formatting. That should probably be a whole other issue discussion, though. 😉 |
|
@PowerShell/powershell-committee reviewed this, we believe a complete solution for transcription (like the unix |
|
Dear Microsoft - when are you going to fix this? @SteveL-MSFT this is critical functionality - how is it "out of scope"? It is critically important that bedrock Microsoft capabilities actually solve problems at scale and this is a huge gap |
|
To complete the picture of the current problems and limitations:
On Unix-like platforms, use of the
However, the # Transcribe an interactive PowerShell user prompt.
# Save the transcript in file .\typescript
script -c 'pwsh -nop -c "read-host prompt"'If you type |
|
Just discovered that Would there be a workaround? |
|
I see the problem in 7.1.0 (as you do), and also still in in 7.2.0-preview.1. Appending |
|
This also does not work for |
|
I was playing with .Net Interactive notebooks & looking into this for why this issue with Notebooks occurs dotnet/interactive#1430 as this is a crucial item that needs fixed before I can recommend to Jupyter Notebooks using .Net Interactive to users in production environments that will have org wide transcription enforced, & I would like to be able to recommend using them without needing to resort to a non-workable workaround cc @SteveL-MSFT |
|
This is pretty disappointing, it's one of those things you expect to just work when you find it, and then you check your log file and it's got 20 lines out of tens of thousands. |
|
Similar problem when you try to run PowerShell 7 code with Start-Transcript from a PowerShell 5 session (not sure if that is the same exact issue as this). You see the output in PowerShell 5 console, but when you check the log file that Start-Transcript output to, it is missing a lot of the output. The same work-around, involving appending |
|
Any dev update on this? I might have stumbled over this error, just wondering if it was fixed in the meantime. |
|
This issue still exists and it is worse than ever. It was not good in PS5 but in PS7 even worse. This is a crutial feature. Please fix it. This issue started before 2015. |
|
@SteveL-MSFT - This issue is still prevalent. I can reproduce the In my case, the workaround of utilising If I append As it appears that there hasn't been any traction on this - for quite some time - is it possible to help the community derive a work-around for the[se] issue[s], until it[they] can be addressed in the code-base? |
|
I hope people understand that if this was easy to fix, we would have done it. The transcription code is more than 10 years old and its design has limitations not easily addressed. The robocopy example above is an example where the NativeCommandProcessor has an optimization where if a native command is at the end of the pipeline, then it doesn't read the stdout pipe and instead just has the exe send the output directly to the console. In this case, transcription is not aware (since PowerShell is not aware) of any output. Piping to a cmdlet works around this optimization. It would actually be easier to create a |
|
Then what's the point of this command if the transcription cannot be relied on? This is just an extreme flaw for a crucial and basic cmdlet |
If it weren't vital functionality, why would the community want it? Your team only fixes easy problems? If it can't be done, remove it (or note it as an experimental, deprecated, or otherwise unreliable cmdlet) |
I'd rather have PowerShell with limited transcript functionality than with none at all. |
|
While I agree that
@SteveL-MSFT currently, the documentation for
Would it be possible to at least list the limitations of the current command, such as not capturing the output from executables in the documentation to save people a lot of time wondering why it's not working as documented? |
|
It does capture executable output, but only 10 lines or so on hundreds. Since it looked like it worked for a few lines of test, I discovered after the fact that all my logs are worthless. |
|
My understanding of the issue is that this is a race. If PowerShell doesn't "flush" output before Regarding workarounds: is it possible to force PowerShell to flush? I would just do it before |
|
Ok i just discovered the reason why the transcript for And it saves absolutely nothing if i pipe to grep ( |
Mmh that's not a bad idea, if that is really the culprit.. so far i tried the following but it didn't do anything, maybe someone knows something more? PS>[console]::OpenStandardOutput().Flush()
PS>[console]::OpenStandardError().Flush()
PS>[console]::Out.Flush()
PS>[console]::Error.Flush() |
|
Yesterday found out that |



Start/Stop-Transcript does not always capture everything written to the console.
I created a github repo with code, repro steps and more context: https://github.com/zammitt/PowerShellTranscriptIssue
Steps to reproduce
In a script file (.ps1)
Here is a script to repro:
The code for Test-TranscriptIssue can be found here: https://github.com/zammitt/PowerShellTranscriptIssue/blob/master/TestIssueOnPowerShellCore/Test-TranscriptIssue.cs
Expected behavior
The contents of the transcript match what was written to the console while the transcript was active.
Actual behavior
The transcript is missing data that was written to the console while the transcript was active.
Environment data
The text was updated successfully, but these errors were encountered: