0

各行に変数を割り当てる WMIC コマンドの出力を取得しようとしています。

出力を次のようにしようとしています。

1 つの最初のプログラムがインストールされました

2 秒プログラムをインストール

3番目のプログラムがインストールされました

4番目のプログラムがインストールされています

5 ...など

@Echo off

wmic /output:file.txt product get name /format:csv

rem wmic product get name

@Echo Off
SetLocal EnableDelayedExpansion
Set n=

Set _InputFile=c:\users\jorge\desktop\file.txt
For /F "tokens=*" %%I IN (%_InputFile%) DO (
Set /a n+=1
Set _var!n!=%%I
)
:: This line will display the variables just assigned
:: For testing only, delete when not needed
Set _
EndLocal

pause
4

1 に答える 1

0

wmic は /f で読み取れない Unicode ファイルを提供するため、これは機能しません (こちらを参照)。回避策は、代わりに ('type file') を使用することです。

@Echo off

:: not really need a csv here...
wmic /output:file.txt product get name /format:table

Set n=0
:: Suggest to use internal call :label rather than delayed expansion
For /F "tokens=* skip=1 delims=" %%I IN ('type file.txt') DO @call :Assign %%I
Set _
pause
goto :EOF

    :Assign
    Set /a n+=1
    Set _var%n% = %*
    goto :EOF
于 2012-07-14T22:43:44.513 に答える