reubenCanowski
reubenCanowski

Reputation: 262

How to create batch file with loop that accepts parameters from text file?

I have a series of crystal reports that needs to be generated based on a propertyID. These reports require 2 parameters (PropertyID and date). I use crystal reports exporter to convert these to pdf to be emailed out.

I need to create a batch file that runs this conversion for each specific property. I've created a txt file with isql containing a column of propertyIDs. I need to make a loop that will read the 1st row of my list of columns then iterate through the rest of the IDs.

This is my first time working with batch files so I'd appreciate any help I can get :) Thanks!

UPDATE: Been working on this some more. And Now I think I'm just having issues with my parameters. For now, I'm just going to start out with one parameter -PropertyID- until I can get a grasp on this. Here is my code as of now.. This is my batch file that runs the conversion of the reports to pdf:

c:
cd c:\y46\crexport #navigating to proper folder
crexport.exe -U username -P password -S server -D dbname -F "C:\y46\crexport\rs_Ardent_Owner_Stmtsputesting.rpt" -O "C:\y46\crexport\output.pdf" -E pdf -a "curr_month:11/01/2012 00:00:00" -a "pscode:%A"

As you can see, my two parameters are being defined here, but pscode(PropertyID) is being set to A (most likely because I'm failing to understand how parameters work). But here is my code I use to call my batch file:

FOR %A IN ("C:\y46\crexport\output.txt") DO "C:\y46\crexport\batch.bat" %A

This works but it's not sending correct parameter values to the batch file so I don't generate any output reports. Also not sure if this is going to loop correctly through each record once I iron out my parameter issues.

Here is another sample of text file source. Just a single column as you can see below. Each row is a propertyID. Some are 3 digits others are 8.

010     
057     
152     
197     
21210721  
21210722    
22090461  
22090462  
22090781  
22090782  
22093561  
22093562  
23180051  
23180052  
23220781  
23220782  
257     
324     
350     
352     
354     
355     
367     
400     
401     
402        

Upvotes: 3

Views: 2634

Answers (1)

Bali C
Bali C

Reputation: 31231

You are almost there, just a few changes are needed

cd C:\y46\crexport
for /f %%a in (file.txt) do (
crexport.exe -U username -P password -S server -D dbname -F "C:\y46\crexport\rs_Ardent_Owner_Stmtsputesting.rpt" -O "C:\y46\crexport\output.pdf" -E pdf -a "curr_month:11/01/2012 00:00:00" -a "pscode:%%a"
)

I have changed the %A on the end to %%a to match the for loop (presuming this is the name of the file currently being processed by the loop.

In short this batch file will process all files in the directory C:\y46\crexport and for each of them run the crexport command that you specified in your question.

If these aren't the right parameter's for crexport then let me know the details and I will tweak it.

Upvotes: 1

Related Questions