【发布时间】:2013-11-30 12:13:33
【问题描述】:
在 Test.txt 内部读取第一行的 URL,还有更多,但这并不重要。
setlocal EnableDelayedExpansion
set browser=chrome.exe
set i=0
for %%f in (Test.txt) do (
set i=0
for /F "delims=" %%l in (%%f) do (
set /A i+=1
set line!i!=%%l
))
::the above read the contents of Test.txt and saved each line to a different Variable made up of two variables
set x=0
:ReadLines
if %x% gtr %i% (
goto Completed)
set /a x+=1
set /a odd=%x%%%2
if %odd%==1 (
set Address=!line%x%!
echo !Line%x%!
::the above echo's back the URL from the Text File
echo %Address%
::but the above here, echo's back nothing at all,(which then is either echo is off or echo is on) even though %Address% has been set to !Line%x%!
pause
::when i try to use !Line%x%! in my code, like the start code below, it returns nothing instead of the URL
start %browser% %Address% >nul 2>&1
start %browser% !Line%x%! >nul 2>&1
::neither start code works unfortunately and that's my ISSUE
ping localhost -n 2 >nul
goto ReadLines
)
:Completed
::Continue or Whatever...
所以我的问题是:有谁知道为什么,当回显时,!Line%x%!返回它应该的值,但是当 调用诸如 start %browser% %Address% 之类的命令,它什么也不返回? 顺便说一句,您可以运行上面的代码,只需将一些链接放在名为“Test.txt”的 txt 文档中,您就会自己看到我的问题 对不起,如果它对任何人来说看起来有点难看,我真的只是为某人把它放在一起,但后来遇到了这个错误,需要为他们解决这个问题。需要任何帮助,谢谢!
【问题讨论】:
-
在这种情况下调试代码时,使用 set 显示所有环境变量的列表。例如,在回显这些值后,在下一行添加一个
set,然后在长列表中查找Address和Line%x%的值
标签: variables batch-file cmd double