http://blogs.msdn.com/b/oldnewthing/archive/2012/07/31/10334556.aspx
for /F "delims=" %%i in ('dir /B /S "%JAVA_HOME%" /a-d ^| findstr jvm.dll') do set "NEW_PR_JVM=%%i"
The /F flag to the FOR command says that it should open the file you pass in parentheses and set the loop variable to the contents of each line.
for /f %%i in (words.txt) do echo [%%i]
The loop variable in the FOR command takes one percent sign if you are executing it directly from the command prompt, but two percent signs if you are executing it from a batch file.
By default, the FOR command sets the loop variable to the first word of each line. If you want to capture the entire line, you need to change the delimiter.
for /f "delims=" %%i in (names.txt) do echo [%%i]
You can put the file name in single quotes to say "Instead of opening this file and reading the contents, I want you to run this command and read the contents."
for /f "delims=" %%i in ('printappdir') do cd "%%i"
for /f %%i in ('printappdir') do set RESULT=%%i
echo The directory is %RESULT%
for /f "tokens=1-2,14" %%i in ('ipconfig') do ^
if "%%i %%j"=="IPv4 Address." set IPADDR=%%k
The above command asked to execute the ipconfig command and extract the first, second, and fourteenth words into loop variable starting with %i. In other words, %i gets the first word, %j gets the second word, and %k gets the fourteenth word.
for /f "tokens=14" %%i in ('ipconfig ^| findstr /C:"IPv4 Address"') do ^
set IPADDR=%%i
In PowerShell
foreach ($i in Get-WmiObject Win32_NetworkAdapterConfiguration) {
if ($i.IPaddress) { $i.IPaddress[0] }
}
for /F "delims=" %%i in ('dir /B /S "%JAVA_HOME%" /a-d ^| findstr jvm.dll') do set "NEW_PR_JVM=%%i"
The /F flag to the FOR command says that it should open the file you pass in parentheses and set the loop variable to the contents of each line.
for /f %%i in (words.txt) do echo [%%i]
The loop variable in the FOR command takes one percent sign if you are executing it directly from the command prompt, but two percent signs if you are executing it from a batch file.
By default, the FOR command sets the loop variable to the first word of each line. If you want to capture the entire line, you need to change the delimiter.
for /f "delims=" %%i in (names.txt) do echo [%%i]
You can put the file name in single quotes to say "Instead of opening this file and reading the contents, I want you to run this command and read the contents."
for /f "delims=" %%i in ('printappdir') do cd "%%i"
for /f %%i in ('printappdir') do set RESULT=%%i
echo The directory is %RESULT%
for /f "tokens=1-2,14" %%i in ('ipconfig') do ^
if "%%i %%j"=="IPv4 Address." set IPADDR=%%k
The above command asked to execute the ipconfig command and extract the first, second, and fourteenth words into loop variable starting with %i. In other words, %i gets the first word, %j gets the second word, and %k gets the fourteenth word.
for /f "tokens=14" %%i in ('ipconfig ^| findstr /C:"IPv4 Address"') do ^
set IPADDR=%%i
In PowerShell
foreach ($i in Get-WmiObject Win32_NetworkAdapterConfiguration) {
if ($i.IPaddress) { $i.IPaddress[0] }
}
No comments:
Post a Comment