【问题标题】:One line of output at a time一次输出一行
【发布时间】:2014-03-26 11:05:18
【问题描述】:

我想在运行此命令时一次获得一行输出。

Invoke-RestMethod -Uri http://blogs.msdn.com/powershell/rss.aspx | Format-Table -Property Title, pubDate

所以我想得到一行输出,然后按EnterAny key 得到下一行输出或按Ctrl+C 中断命令。

我无法通过$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') 实现它

【问题讨论】:

    标签: powershell output-buffering powershell-ise powershell-4.0


    【解决方案1】:

    我会这样做:

     $A = Invoke-RestMethod -Uri http://blogs.msdn.com/powershell/rss.aspx | select -Property Title, pubDate
    FOR ( $I = 0; $I -le $A.Length; $I++ )
    {
        $A[$i] 
        .\pause ""
    }
    

    或一个班轮(看评论)

    Invoke-RestMethod -Uri http://blogs.msdn.com/powershell/rss.aspx |
           select -Property Title, pubDate | 
               % { $_ ; .\pause }
    

    我的 pause.ps1* 文件脚本:

    param([string]$Message="Press any key to continue...")
    Write-Host -NoNewLine $Message
    $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
    Write-Host ""
    

    *这在 ISE 中不起作用。

    【讨论】:

    • 这可以简化为Invoke-RestMethod -Uri http://blogs.msdn.com/powershell/rss.aspx | Format-Table -Property Title, pubDate | foreach { ... }
    • @AyanMullick ISE 中没有任何等价物。您能做的最好的事情就是生成一个带有 OK 按钮的消息框。见here
    猜你喜欢
    • 1970-01-01
    • 2013-07-11
    • 1970-01-01
    • 2017-05-08
    • 2015-10-16
    • 2015-02-11
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    相关资源
    最近更新 更多