China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-24 05:09
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Discussion] ********Question about the Usage of findstr/a******** View 4,427 Replies 22
Original Poster Posted 2007-11-23 22:19 ·  中国 北京 鹏博士BGP
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Seeing that Brother electronixtar posted the ColorDemo.cmd ( http://www.cn-dos.net/forum/viewthread.php?tid=35609&fpage=1 ), there is a line of code that uses findstr to display colorful characters. I really admire the senior's talent. I use findstr rarely. Tonight I found that the use of the /a parameter of this command is a bit strange. By checking the help with findstr /?, the explanation is:

/A:attr Specify the color attribute with hexadecimal digits. Please see "color /?"

Then look at color /?, the explanation is:

attr Specify the color attribute of console output

The color attribute is specified by two hexadecimal digits -- the first is the background, and the second is the foreground.


So, for the /a parameter of findstr, it should be entering two hexadecimal digits. But the actual situation is not like that. I have tried many times and found that four hexadecimal digits are valid (take the last four if there are more than four), while it is not the case after the color command. The latter two digits of these four are easy to understand, that is, as mentioned above, "specify the color attribute of console output", and the first two digits are for what? I found that they are used to control the display of the horizontal lines and vertical lines between the file name strings (including the following colon) (including whether they are present and thickness), but it doesn't seem to be all, because sometimes the first two digits will affect the latter two digits, causing the latter two digits to lose their specified color function (such as 2c04).


TEST: (It seems to form an arithmetic sequence with a common difference of 4)
1. (Horizontal line)
findstr /a:040a . %systemdrive%\boot.ini*


2. (Vertical line)
findstr /a:080a . %systemdrive%\boot.ini*


3. (Horizontal line + vertical line)
findstr /a:0c0a . %systemdrive%\boot.ini*


4. (Vertical line, note the comparison with the second case)
findstr /a:100a . %systemdrive%\boot.ini*


5. (Horizontal line + vertical line, note the comparison with the third case)
findstr /a:140a . %systemdrive%\boot.ini*


6. (Vertical line, note the comparison with the second and fourth cases)
findstr /a:180a . %systemdrive%\boot.ini*


7. (Horizontal line + vertical line, note the comparison with the third and fifth cases)
findstr /a:1c0a . %systemdrive%\boot.ini*


8. Changing to 200a has no horizontal and vertical lines.

9. There are more behind, such as: (it seems to be the same as 1c0a)
findstr /a:dd0a . %systemdrive%\boot.ini*


10. There are also some situations where "the table" has nothing at all, or a very thick vertical line appears at the far right end of the table. Also pay attention to the horizontal and vertical lines on the table border (under different parameters, the border lines may or may not be displayed). Also, sometimes when you slide the scroll bar of the cmd window up to look at the command execution results above and then look back, you will find that the results of the just-executed command below have actually changed! Paranormal event! (such as 5c0a)



Here is another test batch:
@echo off
setlocal
set begin=%1
set end=%2
set step=%3
set colo=%4
if "%4" equ "" (
echo Four parameters:
echo 1. Start value (two hexadecimal): such as 04
echo 2. End value (two hexadecimal): such as 2c
echo 3. Common difference (decimal): such as 4
echo 4. Setting of the last two digits color (two hexadecimal): such as 0a
echo For example: %0 04 2c 4 0a
set begin=04
set end=2c
set step=4
set colo=0a
)
set/a n=0x%begin%
set t=test.tmp
pushd %tmp%
if exist %t% goto :test
for /l %%a in (1,1,5) do echo.^ >>%t%
:test
call :10to16 %n%
if %n% lss 16 (set v=0%r%%colo%) else (set v=%r%%colo%)
echo %v%
findstr/a:%v% . %t%*
echo.
set/a n+=%step%
if not %n% gtr 0x%end% goto :test
popd
pause
goto :eof
:10to16
set/a q=%1
:1c
set/a r=%q%%%16
set/a q=%q%/16
call set r=%%r:10=A%%
call set r=%%r:11=B%%
call set r=%%r:12=C%%
call set r=%%r:13=D%%
call set r=%%r:14=E%%
call set r=%%r:15=F%%
call set r%1=%r%%%r%1%%
if not %q% equ 0 goto :1c
call set r=%%r%1%%
set r%1=



*********************************
Note:
The above conclusions are purely my personal views. Everyone can also try it. What is going on here?

My operating system is:
XP Professional 5.1.2600

[ Last edited by s11ss on 2007-11-23 at 10:35 PM ]
Floor 2 Posted 2007-11-24 12:30 ·  中国 北京 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
It's very similar to debug in DEBUG..
f b800:0000 f9f XX YY
It seems that XX represents the style and YY represents the color.
Floor 3 Posted 2007-11-24 17:42 ·  中国 北京 电信
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Oh? I think this feature can be used to draw tables..................
Floor 4 Posted 2007-11-27 19:48 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
Wow咔咔, it's a rare technical post, I really can't bear to water it down.

That ColorDemo.CMD wasn't written by me, I just reposted it, and I'm not any senior, just an enthusiast for p processing.

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 5 Posted 2007-11-27 20:07 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Now 10to16 doesn't need to be so wordy. If you only convert one digit (0~f), just use the following:
set "Hex=0123456789ABCDEF"
set /a R=
call set R=%%Hex:~%R%,1%%

For converting multiple digits:
@echo off
set "Hex=0123456789ABCDEF"
set /p S=

:10to16
set /a R=S%%16
call set R=%%Hex:~%R%,1%%
set /a S/=16
set C=%R%%C%
if not %S% == 0 goto 10to16

echo %C%
set S=
set R=
set C=
pause


[ Last edited by zh159 on 2007-11-27 at 08:09 PM ]
Floor 6 Posted 2007-11-27 20:08 ·  中国 北京 鹏博士BGP
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Originally posted by electronixtar at 2007-11-27 07:48 PM:
Wow, this is a very rare technical post, I really can't bear to water it down

That ColorDemo.CMD wasn't written by me, I just reposted it, and I'm not any senior, just an enthusiast for P processing.

Brother electronixtar, don't be modest~~ Hey, in your signature
cmd /cstart "" "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Why do I get a "No page to display" prompt when I run this? Also, what are the usages of about:?
Floor 7 Posted 2007-11-27 20:11 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
Originally posted by s11ss at 2007-11-27 20:08:

Brother electronixtar, don't be modest~~ Hey, in your signature

cmd /cstart "" "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>& ...



Then just run iexplore about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'> and try it? Wow haha

[ Last edited by electronixtar on 2007-11-27 at 08:19 PM ]

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 8 Posted 2007-11-27 20:16 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
Originally posted by zh159 at 2007-11-27 20:07:
Now 10 to 16 doesn't need to be so wordy. If you only convert one digit (0~f), use the following which is OK
set "Hex=0123456789ABCDEF"
set /a R=
call set R=%%Hex:~%R%,1%%

For converting multiple digits: ...

:P I don't understand, awesome, I haven't been here for a long time and the experts are still so powerful

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 9 Posted 2007-11-27 20:25 ·  中国 湖南 长沙 电信
初级用户
Credits 67
Posts 32
Joined 2007-11-19 12:34
18-year member
UID 103118
Gender Male
Status Offline
Originally posted by electronixtar at 2007-11-27 08:11 PM:

Try directly running iexplore about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>? Wow haha

[ Last edited by electronixtar on 20 ...



We can't get it to run no matter how we reference it. If we could run some program on your computer like this, heh heh, you'd be in trouble
Floor 10 Posted 2007-11-27 20:28 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
Originally posted by upsco at 2007-11-27 20:25:

We can't get it to run no matter how we reference it. If we could run a certain program on your computer like this, heh heh, you'd be in trouble

Then you must not have installed any version of Microsoft Office 2000/XP/2003/2007

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 11 Posted 2007-11-27 20:30 ·  中国 北京 鹏博士BGP
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Brother zh159, your code for converting multiple digits isn't necessarily less wordy than mine~~~~~~~~
No, I take that back.
Actually, each has its own advantages and disadvantages.
Yours is simple but reduces code readability, and mine is wordy but improves code readability.

[ Last edited by s11ss on 2007-11-27 at 08:46 PM ]
Floor 12 Posted 2007-11-27 20:33 ·  中国 北京 鹏博士BGP
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Originally posted by electronixtar at 2007-11-27 08:28 PM:

Then you must not have installed any version of Microsoft Office 2000/XP/2003/2007.

I installed Microsoft Office 2003. It seems to be a modified version.
Floor 13 Posted 2007-11-27 20:42 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
s11ss +2 2007-11-27 21:48
Floor 14 Posted 2007-11-27 20:51 ·  中国 北京 鹏博士BGP
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Brother zh159, your code for converting multiple digits is no less wordy than mine~~~~~~~~
I'm sorry, I take that back.
Actually, each has its own advantages and disadvantages.
Yours is simple but reduces code readability and increases "program processing volume" (replaces 0-9), and mine is wordy but improves code readability.
Floor 15 Posted 2007-11-27 20:54 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
I also wrote one
SETLOCAL ENABLEDELAYEDEXPANSION
IF %1 GTR 2099999999 (GOTO :EOF)
SET VAR=0123456789ABCDEF
FOR /L %%i IN (0,1,15) DO (
SET H%%i=!VAR:~%%i,1!
SET HH=1&SET KK=0&SET TT=%1
:th1
SET /A HV%HH%=%TT%/16,HV%KK%=%TT%%%16
IF !HV%HH%! GTR 16 (SET TT=HV%HH%&&SET /A HH+=1,KK+=1&&GOTO TH1)
SET VAR1=0x00!H%HV9%!!H%HV8%!!H%HV7%!!H%HV6%!!H%HV5%!!H%HV4%!!H%HV3%!!H%HV2%!!H%HV1%!!H%HV0%!
ECHO %VAR1% ^<^<=%0
GOTO :EOF
Forum Jump: