You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从PowerShell/CMD自定义应用输出中提取动态Id值

提取应用输出中的Id数值

PowerShell 实现

直接捕获应用输出,通过正则匹配提取Id:

# 替换为你的自定义应用路径/名称
$appOutput = .\YourCustomApp.exe
$extractedId = $appOutput | Select-String -Pattern '^\s*(\d+)\s+Static' | ForEach-Object { $_.Matches.Groups[1].Value }
# 输出结果
$extractedId

原理:利用Select-String匹配Id所在行(特征是数字后紧跟Static),捕获分组中的纯数字部分就是目标Id。

CMD 实现

通过管道结合findstr和for命令提取,无需临时文件:

@echo off
for /f "tokens=1" %%a in ('YourCustomApp.exe ^| findstr "Static"') do set "extractedId=%%a"
echo %extractedId%

原理:先用findstr过滤出包含Static的行(即Id所在行),再用for /f取该行第一个字段,也就是Id数值。

内容的提问来源于stack exchange,提问作者George

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 03:52:01