使用特定字符串记录文件后如何从 powershell 打开网页?
How to open a webpage from powershell once a file is logged with a particular string?
我必须从 powershell 打开 2 URLs。每个创建一个日志文件。第一个 URL 的日志文件完成后,必须启动第二个 URL。文件的完成由字符串 "end of log" 指示。每个日志至少需要 15 分钟。由于不确定持续时间,我没有使用sleep commanlet。
好的,这很简单,您使用 Select-String
在文本文件中搜索字符串。您在 while
块中执行此操作,因此 while Select-String returns false (-Quiet
使 cmdlet return 为 bool true 或 false,如果该值存在在文件中)等待一段时间,然后再次检查。
While ($(Select-String -Path 'C:\Logs\File1.txt' -Pattern 'end of log' -quiet) -eq $False)
{
Write-Host "No end of log in file 1 waiting.."
Sleep -Seconds 3
}
由于您的第一个脚本需要 15 分钟才能完成,您可能希望让它在两次检查之间等待更长时间,因为如果它频繁出现,可能会减慢第一个脚本的速度。
我必须从 powershell 打开 2 URLs。每个创建一个日志文件。第一个 URL 的日志文件完成后,必须启动第二个 URL。文件的完成由字符串 "end of log" 指示。每个日志至少需要 15 分钟。由于不确定持续时间,我没有使用sleep commanlet。
好的,这很简单,您使用 Select-String
在文本文件中搜索字符串。您在 while
块中执行此操作,因此 while Select-String returns false (-Quiet
使 cmdlet return 为 bool true 或 false,如果该值存在在文件中)等待一段时间,然后再次检查。
While ($(Select-String -Path 'C:\Logs\File1.txt' -Pattern 'end of log' -quiet) -eq $False)
{
Write-Host "No end of log in file 1 waiting.."
Sleep -Seconds 3
}
由于您的第一个脚本需要 15 分钟才能完成,您可能希望让它在两次检查之间等待更长时间,因为如果它频繁出现,可能会减慢第一个脚本的速度。