回复 5# tmplinshi
很好的东西,有做正则表达式,虽然只是字符串替换,但呈现的特性是美丽的,有求字符串长度的折半算法,实用性高,因为论坛经常有人问生成随机字符串的问题,也有标准exe的感觉,帮助内容很规范。
好的东西需要推广和完善,需要经得起实践的检验,建议以函数(实际为代码块)的方式发布,毕竟bat和exe是不一样的,如:
1.按照使用一般命令的习惯,使用者一般会忘记用call调用,如下的代码就会导致echo,456得不到执行:- @echo off
- echo,123
- rstr.bat
- echo,456
复制代码 正确的用法:- @echo off
- echo,123
- call,rstr.bat
- echo,456
复制代码 同理,因为忘记用call调用,会开启新的cmd进程执行rstr.bat,如下的代码会产生含执行路径的输出,影响效果或其他:- @echo off
- for /l %%a in (1 1 5) do rstr
复制代码 输出:- da84f0qq8s
-
- e:\test>rstr
- tv78846dp3
-
- e:\test>rstr
- nxpx0f6hk0
-
- e:\test>rstr
- jutis5882j
-
- e:\test>rstr
- aun0gda121
复制代码 正确的用法:- @echo off
- for /l %%a in (1 1 5) do call,rstr
复制代码 2.可能因为在很小的时间间隔内做相同的初始化工作的原因,如下的代码会产生重复的字符串,原因不明,猜测同一bat会分配相同的资源给for/f的命令部分使用。- @echo off
- for /f "delims=" %%b in ('rstr') do echo,%%b
- for /f "delims=" %%b in ('rstr') do echo,%%b
- for /f "delims=" %%b in ('rstr') do echo,%%b
- for /f "delims=" %%b in ('rstr') do echo,%%b
- for /f "delims=" %%b in ('rstr') do echo,%%b
- for /f "delims=" %%b in ('rstr') do echo,%%b
- for /f "delims=" %%b in ('rstr') do echo,%%b
- for /f "delims=" %%b in ('rstr') do echo,%%b
- for /f "delims=" %%b in ('rstr') do echo,%%b
- for /f "delims=" %%b in ('rstr') do echo,%%b
- for /f "delims=" %%b in ('rstr') do echo,%%b
- for /f "delims=" %%b in ('rstr') do echo,%%b
- for /f "delims=" %%b in ('rstr') do echo,%%b
- for /f "delims=" %%b in ('rstr') do echo,%%b
- for /f "delims=" %%b in ('rstr') do echo,%%b
- for /f "delims=" %%b in ('rstr') do echo,%%b
- for /f "delims=" %%b in ('rstr') do echo,%%b
- for /f "delims=" %%b in ('rstr') do echo,%%b
- for /f "delims=" %%b in ('rstr') do echo,%%b
- for /f "delims=" %%b in ('rstr') do echo,%%b
复制代码 输出:- 3rggb4hzgo
- 3rggb4hzgo
- 3rggb4hzgo
- 3rggb4hzgo
- 3rggb4hzgo
- 3rggb4hzgo
- frwrek6nok
- frwrek6nok
- frwrek6nok
- frwrek6nok
- frwrek6nok
- frwrek6nok
- frwrek6nok
- frwrek6nok
- frwrek6nok
- frwrek6nok
- frwrek6nok
- frwrek6nok
- frwrek6nok
- frwrek6nok
复制代码
|