最近在写一个关于文本方面的批处理文件,遇到了个难题,请教各位大侠们。
先谢谢您抽时间往下阅读
步骤:
(1)先将以下部分cut,存名为“tt.txt”文件,注意这个文件只有一行,可能会由于屏幕大小的问题会在某些显示器上显示为多行。- document.write('| <a href="http://passport.baidu.com/?login&tpl=sp&tpl_reg=sp&u=http://hi.baidu.com' + encodeURIComponent('/huiclear/blog/item/4cd78c1059c7c504213f2e26%2Ehtml') + '">登录</a>');
复制代码 (2)cut以下部分,存名为“test.bat”的bat文件。- setlocal enabledelayedexpansion
- for /f "tokens=*" %%i in (tt.txt) do (set var=%%i
- call echo "!var!"
- )
- pause
复制代码 (3)运行这个批处理文件。(不知跟你假想的结果一样不一样,反正我是意想不到的)
结果:
运行的结果竟和在CMD下运行 call /? 的结果一致。
问题:
请以红色部分为关键点来着手回答问题,谢谢。
(1)call的问题——为什么会出现这种结果,请分析一下,最好能详细点。
在处理以下见面代码时,也会遇到同样的问题- document.write(" <a href='http://passport.baidu.com/?reg&tpl=sp&return_method=get&skip_ok=1&u=http://hi.baidu.com/sys/reg/' target='_blank'>注册</a>");
复制代码
- document.write(' | <a href="http://passport.baidu.com/?login&tpl=sp&tpl_reg=sp&u='+myref+'">登录</a>');
复制代码 (2)call的问题——如何能正确地将tt.txt的内容出来,要求要有变量var的存在。
(*3)题外话set的问题——我先抛弃tt.txt这个文件,再将test.bat的代码改为以下部分,却又不能出现与运行 call /? 一样的结果了。那如何又能再出现与 cmd /? 一样的结果呢?- setlocal enabledelayedexpansion
- set var=document.write('| <a href="http://passport.baidu.com/?login&tpl=sp&tpl_reg=sp&u=http://hi.baidu.com' + encodeURIComponent('/huiclear/blog/item/4cd78c1059c7c504213f2e26%2Ehtml') + '">登录</a>');
- call echo "!var!"
- pause
复制代码 以下两种也都试过了- set var="document.write('| <a href="http://passport.baidu.com/?login&tpl=sp&tpl_reg=sp&u=http://hi.baidu.com' + encodeURIComponent('/huiclear/blog/item/4cd78c1059c7c504213f2e26%2Ehtml') + '">登录</a>');"
复制代码
- set "var=document.write('| <a href="http://passport.baidu.com/?login&tpl=sp&tpl_reg=sp&u=http://hi.baidu.com' + encodeURIComponent('/huiclear/blog/item/4cd78c1059c7c504213f2e26%2Ehtml') + '">登录</a>');"
复制代码 (*4)扩展——处理网页代码时都该注意些什么,有没有什么可以参考的。
------------------------------------------------------------------------------------------------
万分感谢您能一路阅读到这里,辛苦了。谢谢。
------------------------------------------------------------------------------------------------
[ 本帖最后由 wuming 于 2008-12-3 13:09 编辑 ] |