gpt4 book ai didi

powershell - 从拖尾日志中选择一个字符串

转载 作者:行者123 更新时间:2023-12-03 01:14:45 25 4
gpt4 key购买 nike

我有一个应用程序日志,我正在尝试为其编写一个批处理文件,该文件将尾随日志并返回包含“队列大小”的字符串,以便可以显示更新队列的大小。 Windows基本上相当于:

tail -f app.log | grep "queue size"

从我读过的书中,我将需要使用Windows powershell。我设计了以下脚本:
powershell -command Select-String -Path C:\logs\app.log -Pattern "queue size"

这给了我以下错误:

Select-String : A positional parameter cannot be found that accepts
argument 'size'. At line:1 char:1
+ Select-String -Path C:\logs\app.log -Pattern queue size
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Select-String], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SelectStringCommand

尽管目前这种方法行不通,但是会根据当前逻辑不断更新吗?

最佳答案

您需要将命令用双引号引起来,并将单引号用于模式:

powershell -command "Select-String -Path C:\logs\app.log -Pattern 'queue size'"

关于powershell - 从拖尾日志中选择一个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32452738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com