views:

143

answers:

2

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 the 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.

+2  A: 

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.

Joey
very clever! ...
PA
it worked, thanks.I know is the same thing renaming the file to .cmd, just wanted to create an .exe file.
Splash
There are tools out there to create executables from batch files.
Joey
A: 

just rename test.txt to test.bat and run it.

PA
@johannes.. you won by 23 secs!
PA
even if the @echo off option is enabled the command prompt window still appears, before the archive is opened, if I create a little app that runs in the background the only thing visible to the user is the download button and the application that handles the archives.
Splash
you can run a .bat file without opening a command prompt. See the START command.
PA