Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi
I need to pass arguments from a txt file to a batch file. The txt file will contain multiple lines, each line will have: un & emaill add.
How do I get a batch file to call the arguments and process line by line till end of file?
your help would be much appreciated!!.Thnaks in advance!

Change the name of the text.txt to match the name of your text file.
@echo off
for /f "tokens=*" %%a in (text.txt) do %%a

what im trying to do is a basic sharepoint site restore, not sure if your familiar with the stsadm command, but basically the batch file command is as follows:
stsadm -o createsite -url http://my-site.company.com/personal/%1 -ownerlogin domain\%2 -owneremail %3
so basically I have a txt file with %1, %2 & %3 (accross 1 line) in a tab-del txt file, its a list with a couple of hundred entries.
Id like the batch file to run the above command and grab the enries from the txt file as it completes each line.
can you help with this? thanks!

@echo off & setLocal EnableDELAYedExpansion
for /f "tokens=1-3 delims= " %%a in (myfile) do (
stsadm -o createsite -url http://my-site.company.com/personal... -ownerlogin domain\%%b -owneremail %%c
)
=====================================
Helping others achieve escape felicityM2

Hi thanks for your help with this, but that command doesnt seem to work. Not sure if the %%a, %%b etc is causing an issue for the stsadm command.
I have pasted below from the command window
******************************************E:\MySites>mysites.bat
ECHO is on.E:\MySites>for /F "tokens=1-3 delims= " %a in (users_tabDel.txt) do (stsadm -o c
reatesite -url http://my-site-stg.company.com/pers... -ownerlogin DOMAIN\%b -
owneremail %c@COMPANY.com )E:\MySites>(stsadm -o createsite -url http://my-site-stg.company.com/pers... username firstn.lastn -ownerlogin DOMAIN\ -owneremail @company.com )
Command line error.
************************************************
(between the aster's is what was pasted from the command windows)any ideas? seems when it runs the stsadm command the parameters are translated incorreclty?

Use the script I posted but put ECHO before the stsadm. Then run it and paste the output.
=====================================
Helping others achieve escape felicityM2

This is a Tab delimited file? It looks to me that a space is being used as a delimiter instead of a tab, therefore the whole line is %%a.
If it's the case all that needs to be done is replace the space after "=" in "delims=" with a tab so the line gets split up correctly.
M2's script isn't in pre tags so the tab would have been converted to space on the forum.

Hi...thanks for your continued help with this!
So I put the ECHO before the stsadm cmd and then changed the space after the = to be a tab. Still an issues exists, see below
***********************************************
E:\MySites>mysites.bat
ECHO is on.E:\MySites>for /F "tokens=1-3 delims= " %a in (users_tabDel.txt) do ECHO(
E:\MySites>ECHO(
E:\MySites>stsadm -o createsite -url http://my-site-stg.company.com/pers...
a -ownerlogin DOMAIN\%b -owneremail %c@company.comThe user or group 'DOMAIN\%b' is unknown.
E:\MySites>
*******************************************************I can convert the tab-del txt file to comma separated if it will make it easier? pls advise
thanks again!

Hi Guys...any ideas on the above? been trying to solve it to no avail...your help is much appreciated...

I'm just going to re-post M2's script inside pre tags because the
way the url gets truncated is not helpful:for /f "tokens=1-3 delims= " %%a in (myfile) do ( stsadm -o createsite -url http://my-site.company.com/personal/%%a -ownerlogin domain\%%b -owneremail %%c )I realy can't see anything wrong with it...

Is Tab a default limiting character? Editing Mechanix2Go's script:
@echo off & setLocal EnableDELAYedExpansion for /f "tokens=1-3" %%a in (myfile) do ( stsadm -o createsite -url <a href="http://my-site.company.com/personal/%%a" target="_blank">http://my-site.company.com/personal...</a> -ownerlogin domain\%%b -owneremail %%c )If it doesn't work try to convert the tab-del txt file to comma separated one and execute this:
@echo off & setLocal EnableDELAYedExpansion for /f "tokens=1-3 delims=," %%a in (myfile) do ( stsadm -o createsite -url <a href="http://my-site.company.com/personal/%%a" target="_blank">http://my-site.company.com/personal...</a> -ownerlogin domain\%%b -owneremail %%c )Gaetano
PS: correct the stsadm before copying it: I can't avoid the catching of the url...

The default delims are space & tab.
=====================================
Helping others achieve escape felicityM2

Hi Guys...
Still having trouble...so ive tried all of the above in various combos and still gettign same results. Maybe im doing something wrong...not sure.
But here is what is in the cmd window:
**********************************
E:\MySites>mysites.bat
ECHO is on.E:\MySites>for /F "tokens=1-3 delims=," %a in (users_tabDel.txt) do ECHO(
E:\MySites>ECHO(
E:\MySites>stsadm -o createsite -url href="http://my-site-stg.company.com/per
sonal/%a" target="_blank" -ownerlogin DOMAIN\%b -owneremail %c@company.com 0<a 1>
http://my-site.company.com/personal/a
The system cannot find the file specified.
E:\MySites>
**************************************************
Here is exactly what I have in the batch file:
***************************************************
@echo & setLocal EnableDELAYedExpansionfor /f "tokens=1-3 delims=," %%a in (users_tabDel.txt) do ECHO(
stsadm -o createsite -url http://my-site.company.com/personal/a -ownerlogin DOMAIN\%%b -owneremail %%c@company.com
)
*******************************************************
and here is what I have in the txt file:
(only one line for the moment whilst testing)
********************************************************
username,username,firstname.lastname
*********************************************************Thanks!

Guys thanks for all your help, got it licked finally!
so this is what worked in the end:
**************************************************
@echo onFOR /f "tokens=1-3" %%a in (e:\mysites\sites.txt) do @stsadm -o createsite -url http://my-site.company.com/personal... -ownerlogin "DOMAIN\%%b" -owneremail "%%c@company.com"
@echo off
**************************************
Thanks for all your help!...much appreciated!!

Oh and as you can see, seems it was the " " around the domain\... and around the email that did it in the end...
thx

No idea why you're using echo on. [It's already on.] Nor why you're using echo off at the end.
And %%a never gets used. LOL
But if it blows your dress up, I'm all for it.
=====================================
Helping others achieve escape felicityM2

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |