I have this test.txt file with the following content:
@echo off
wget -q http://subs.ro/get/21518
move 21518 %userprofile%/Desktop/21518.zip
%userprofile%/Desktop/21518.zip
This file is generated by a javascript and the content keeps changes. I have th开发者_如何学运维e following text.bat file :
for /F "eol=; tokens=1* delims=" %%i in ( test.txt ) do %%i
the problem is that the link to the desktop is not recognized because the system variable %userprofile% is not recognized, is pasted as a txt string. I am using this setup because I want to convert the bat file to a exe and create an invisible application that does everything in the background.
Why not rename the file to test.cmd
and run it directly?
The following should work, though:
@echo off
for /F "eol=; tokens=1* delims=" %%i in ( test.txt ) do call :run %%i
goto :eof
:run
%*
goto :eof
The reason here is that for
itself doesn't expand environment variables in its variables. Probably the only point in batch where this is the case. So I'm just handing the line to a subroutine (run
), which does the executing for me.
just rename test.txt to test.bat and run it.
精彩评论