Clear-RecycleBin cmdlet's progress bar output is shown incorrectly

╄→尐↘猪︶ㄣ 提交于 2020-07-20 03:52:26

问题


Is the first time I'm using the Clear-RecycleBin cmdlet, and it seems obvious that this cmdlet paints a typical command-line progress bar that I think it should be filled with symbols or maybe color blocks from start to end, or maybe it should just print a percentage value in the middle of the bar, I don't know exactly because as I'm saying is the first time I'm using this cmdlet, however, seeying the image below its obvious the progress bar output is wrong. The proggress-bar is totally "static", it does not fill the bar, it just prints (at once) a couple of characters and it does not continue printing more of them, as shown in this image:

I tested the cmdlet various times by sending thousands of files to the recycle-bin, this way I force the cmdlet to take its time (in minutes) to finish the recycle operation, and I noticed it does not matter how many time is elapsed while this cmdlet is working, the progress bar output is always the same. Only that amount of "o" characters are printed, and they are printed instantly, not progressively.

I thought that maybe it could be some kind of output encoding issue, otherwise this weird progress bar output seems inexplicable for me...

I'm not sure what is wrong. This is the way I'm running this cmdlet:

PowerShell.exe -command "[console]::WindowWidth=40; [console]::WindowHeight=6; [console]::BufferWidth=[console]::WindowWidth; Clear-RecycleBin -DriveLetter 'C' -Force -ErrorAction SilentlyContinue; Start-Sleep -Second 2"

My question is: why I'm having this output and how do I fix it?


回答1:


why I'm having this output and how do I fix it?.

You're having this output because the author of Clear-RecycleBin deliberate deceives you, and you can't really do anything to fix it.

Clear-RecycleBin basically does the following:

  1. Prepare status messages
  2. Set Progress to 30%
  3. Call shell32.dll!SHEmptyRecycleBin()
  4. Set Progress to 100%

The call to SHEmptyRecycleBin() is a blocking call (ie. control will only be returned to the caller on completion), and the cmdlet really has no way of relaying the ongoing progress back to the caller because the progress UIs in shell32.dll are tightly integrated with the desktop shell by-design, and not really designed to be consumed or instrumented in any other context.



来源:https://stackoverflow.com/questions/58376254/clear-recyclebin-cmdlets-progress-bar-output-is-shown-incorrectly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!