バッチ処理の中でパワーシェルでテキストファイルを読んで文字列に一致した先頭行番号を返す
バッチファイル
SET contents=0
FOR /F "usebackq" %%a IN (`powershell -command "$lineNumber = ((Get-Content '%~f0')[6..((Get-Content '%~f0').Length - 1)] | ForEach-Object { $_ } | Select-String -Pattern 'arg1' -SimpleMatch | Select-Object -First 1).LineNumber;Write-Output $lineNumber"`) DO (
SET contents=%%a
)
echo %contents%
timeout /t 5&goto:eof
arg1
arg2
サンプルでは自分自身のバッチファイルを読んでいますかテキストファイルの場所を変えてください
ディスカッション
コメント一覧
まだ、コメントがありません