Batch Loop Help

Sup Sup Forums,

I have an old Windows machine I need to automate something on, bash and powershell aren't available to me, and I'm not sure how to do what I'm trying to do with only batch scripting available.

essentially, I'd like to have somewhere, in the batch file, in a text file, wherever

arg1 arg2 arg3 etc.

and have the batch file repeatedly execute...

command $arg staticarg anotherstaticarg

...until there are no arguments left.

Yeah, I know I can just do

command $arg1 staticarg anotherstaticarg
command $arg2 staticarg anotherstaticarg
command $arg3 staticarg anotherstaticarg

...but the list of variable arguements is likeky going to change often, so I don't want to do that.

Any ideas Sup Forums?

Should I just install Cygwin and do this in bash?

Other urls found in this thread:

en.wikibooks.org/wiki/Windows_Batch_Scripting#FOR
frippery.org/busybox/
twitter.com/AnonBabble

lrn2goto

why would you waste your time with batch when you already know you can do it in bash?

batch was not meant for this sort of thing.

RTFM
en.wikibooks.org/wiki/Windows_Batch_Scripting#FOR

I know, I've just been asked to "not install anything" unless I absolutely have to.

Just kill that NT4 box

This is a stupid idea. You don't understand CMD, aren't really a hot shit programmer. You'll probably wreck shit if you use it.

Install bash & play it safe.

Yeah I've looked at this, but have no idea where to even start, I haven't touched batch in around 20 years.

I'm probably going to just use Windows task scheduler to make a different machine on the network (that has Cygwin) generate a crappy batch file using the...

command $arg1 staticarg anotherstaticarg
command $arg2 staticarg anotherstaticarg
command $arg3 staticarg anotherstaticarg

...method.

2000 Advanced Server, you were close.

It has to do with DNR reporting at the water department.

Haven't used cmd once but maybe you can try this by putting each arg on new line on list.txt.
for /f "tokens=*" %%a in (list.txt) do @command %%a staticarg anotherstaticarg

I'm a batch programmer so I think I can help, but you are going to have to give me more to work with because I don't understand what you are trying to achieve here.

Explain in baby steps exactly what you want this script to do and I will post you the code to do it.

>%i is to be used from the command line while %%i is to be used from a batch
Who thought of this?

fixedtext $variabletext fixedtext fixedtext

I'm going to be executing the same command multiple times.

Argument 2 and argument 3 will always be the same.

Argument 1 is dymanic, I'd like to retrieve it from somewhere, I don't care where.

...

This worked for what I want to do, thanks.

You install a GNU/Linux distro on it so that """old'''''' computer will feel as new again. The you google how bash works and solve your problem in 1 minute.

for /f "delims=" %%X in ('args.txt') do (command %%X staticarg anotherstaticarg)

I'm using gov. provided software on a server I don't own. Said software only runs on Win2k Adv. Server

I already know how bash works :-)

best of luck, user!

OP if possible, you can run a somewhat limited bash via busybox for windows
frippery.org/busybox/

The bash is kinda old, but it beats scripting with Batch.

I've already finished what I was trying to accomplish, this did what I needed.

Irrelevant to OP's question, do you know a batch interpreter that can be run on Linux?

Download busybox.exe and do it in the busybox shell. It's under a megabyte.

$ wine cmd

Don't question it it's microsoft, probablly some weird compatibility issue.