为什么“写入主机”与PowerShell函数和计时器处理程序的工作方式不同?

时间:2018-11-15 07:31:17

标签: powershell

我有1809个装有PowerShell Core 6.1.1的Windows 10包装盒 给定以下代码示例:

public void mouseMoveToExpandIcon(){
        Actions action = new Actions(driver);
        action.moveToElement(expandButtonXpath).perform();
    }

如果我调用“测试”功能,则会按预期获得“测试”输出:

enter image description here

但是,如果我安排使用计时器进行调用,命令提示符将完全混乱:

enter image description here

我隐约地了解到这与内部“ readline”和控制台机制有关,但是它是通过Powershell中的计时器/句柄生成换行输出并紧跟命令提示符的任何方式吗?

1 个答案:

答案 0 :(得分:-2)

Register-ObjectEvent -InputObject $timer -EventName Elapsed -SourceIdentifier Timer.Test -Action {
    Test
  }

$timer.Enabled = $true

PS C:\> $Subscriber = Get-EventSubscriber -SourceIdentifier Timer.Test
PS C:\> $Subscriber.action | Format-List -Property *

command属性应包含“测试”功能的结果。

以下网址有详细说明。 https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-eventsubscriber?view=powershell-6