Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
tinfanide
- Posts: 117
- Joined: 05 Sep 2011 09:15
#1
Post
by tinfanide » 28 Feb 2012 21:27
Code: Select all
@echo off
Setlocal
For /F %%a in ('wmic baseboard GET SerialNumber /value^|find "SerialNumber"') do Set %%a
@echo %Computername% - %SerialNumber%
endlocal
PAUSE
I've looked up in CMD
But what if they come together? And how does it interact with FIND?
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#2
Post
by foxidrive » 28 Feb 2012 22:38
^ is also the escape character in batch files.
echo ^&
The above will echo an & to the console. It is necessary to escape some certain poison characters in certain places so you can echo them; and in the case of a for next loop with a command, when using a redirection character or pipe or ampersand, then it is necessary to escape them in the command tail.
This will work in a batch file
for /f %%a in (' echo aaa ^| find "a" ') do echo %%a
but this will fail, even though the syntax of the command inside the quotes is vaild for normal parts of a batch file.
for /f %%a in (' echo aaa | find "a" ') do echo %%a
I hope that's cleared it up a bit.
-
tinfanide
- Posts: 117
- Joined: 05 Sep 2011 09:15
#3
Post
by tinfanide » 28 Feb 2012 22:48
foxidrive wrote:^ is also the escape character in batch files.
echo ^&
The above will echo an & to the console. It is necessary to escape some certain poison characters in certain places so you can echo them; and in the case of a for next loop with a command, when using a redirection character or pipe or ampersand, then it is necessary to escape them in the command tail.
This will work in a batch file
for /f %%a in (' echo aaa ^| find "a" ') do echo %%a
but this will fail, even though the syntax of the command inside the quotes is vaild for normal parts of a batch file.
for /f %%a in (' echo aaa | find "a" ') do echo %%a
I hope that's cleared it up a bit.
Yes, it's clear to me now. Thanks for your quick reply.