[英]Powershell if statement in pipeline
I am in need to create a script which can continuously read a file and if a certain line with text comes, to call a function. 我需要创建一个可以连续读取文件的脚本,如果有一行带有文本,则调用一个函数。
I am thinking in a way to do this a single line thing with 我正在想办法用一条线来做这件事
Get-Content -Path $logFile -wait | ?{$_-match "$filter"}
but I am not aware of a way to call a function if the line does answer the criteria. 但如果线路确实符合标准,我不知道如何调用函数。
Is that doable ? 那可行吗? or I should do it like in a loop to read the file every cycle and if there is a match to exit the loop ? 或者我应该像循环一样在每个周期读取文件,如果有匹配退出循环?
将它传递给foreach循环,它将分别遍历每一行,您可以将if语句放在循环中:
Get-Content -Path $logFile -wait | %{if($_ -match "$filter"){Callfunction}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.