Page 1 of 1

Help with fetching a command from a remote text-file.

Posted: 17 Sep 2011 17:23
by Enigma_
For some reason, this code:

Code: Select all

for /f "delims=" %a in ('URL2FILE http://www.website.com/file.txt ^| findstr /v "linux"') do @%a

Works perfectly fine from the command line, but will fail when I use it in a batch file. :s

Basically it's supposed to fetch the file's contents, and feed them into the variable and the variable is executed as a line of code.

So, for example, I could use this in an simple auto-updator for a program, or client.
This would fetch the code from the file which would instruct the batch file to download the new file version, or the current dependencies.
This could also be used to fetch 'users' from a list.
There are a few other things it could be used for, but they're moot.


Essentially, I'm just looking for some insight as-to why it doesn't seem to work in a batch file.
As well as a fix, if possible.
If not, I'd be immensely appreciative if somebody could provide an ulterior means of accomplishing what I'm aiming for.

Re: Help with fetching a command from a remote text-file.

Posted: 17 Sep 2011 19:46
by dbenham
The answer is in the HELP contents (relevant part highlighted in blue):

>HELP FOR
Runs a specified command for each file in a set of files.

FOR %variable IN (set) DO command [command-parameters]

%variable - Specifies a single letter replaceable parameter.
(set) - Specifies a set of one or more files. Wildcards may be used.
command - Specifies the command to carry out for each file.
command-parameters - Specifies parameters or switches for the specified command.

To use the FOR command in a batch program, specify %%variable instead
of %variable.
Variable names are case sensitive, so %i is different
from %I.

etc....



Dave Benham

Re: Help with fetching a command from a remote text-file.

Posted: 20 Sep 2011 16:29
by Enigma_
Thank you for your help.
I've got to say, I feel very...Foolish. >_<

I guess it was a simple mistake, but apparently the people on these forums are patient enough to deal with me. :)

Once again, thank you!