ben1211
asked on
Removing Spaces in a Batch File
Previously I had asked a question on how I can replace the Execution date with a date entered by the user. Basically it is to write the Execution Date & Execution Month into the text file called batch_bo_report_param.txt. The text file looks like this:
BOUSER=bouser
BOPASS=bouser
Execution Date (YYYY-MM-DD) : =2005-03-28
Execution Month (YYYY-MM) : =2005-03
Batch Bo Report Path: =C:\MDB_BATCH_BO_REPORTS\R eport\
Log Batch Bo Report Path: =C:\MDB_BATCH_BO_REPORTS\L og\
Batch Result Bo Report Path: =C:\MDB_BATCH_BO_REPORTS\R esult_Repo rt\
Logo Path Name : =C:\MDB_BATCH_BO_REPORTS\P aram\KLLog o.bmp
I was given the code by obda:
@echo off
setlocal
set InputFile=c:\batch_bo_repo rt_param.t xt
set OutputFile=c:\batch_bo_rep ort_param- new.txt
set NewExecutionDate=2005-05-1 0
if exist "%OutputFile%" del "%OutputFile%"
for /f "tokens=1,2*" %%a in ('type "%InputFile%"') do (
if /i "%%a %%b"=="Execution Date" (
>>"%OutputFile%" echo Execution Date ^(YYYY-MM-DD^) : =%NewExecutionDate%
) else (
>>"%OutputFile%" echo %%a %%b %%c
)
)
Now the code works fine. It actualy creates a new batch_bo_report_param file and replaces the Execution Date. This batch_bo_report_param.txt file is actually used to pass certain data to some other file. Anyway, I normally run another batch report (CTPD950.bat) which in turn gets its Execution date from the batch_bo_report_param.txt file.
The problem is, the CTPD950.bat file will not run when this new param file is created. So I tested it out by cutting the exact lines (posted right above) and pasted it in the new batch_bo_report_param.txt file and the report CTPD950 ran. The four lines that I cut and pasted from the old batch_bo_report_param.txt file to the new one are:
BOUSER=bouser
BOPASS=bouser
Execution Date (YYYY-MM-DD) : =2005-03-28
Execution Month (YYYY-MM) : =2005-03
Is there any possible way of doing like a vbCrLf for a DOS batch file? I suspect this may be the cause, but I am uncertain. There is something about these four line that is causing the CTPD950.bat report not to run when it reads the newly created batch_bo_report_param.txt
I really need help on this as I am totally out of ideas.
Thank You
BOUSER=bouser
BOPASS=bouser
Execution Date (YYYY-MM-DD) : =2005-03-28
Execution Month (YYYY-MM) : =2005-03
Batch Bo Report Path: =C:\MDB_BATCH_BO_REPORTS\R
Log Batch Bo Report Path: =C:\MDB_BATCH_BO_REPORTS\L
Batch Result Bo Report Path: =C:\MDB_BATCH_BO_REPORTS\R
Logo Path Name : =C:\MDB_BATCH_BO_REPORTS\P
I was given the code by obda:
@echo off
setlocal
set InputFile=c:\batch_bo_repo
set OutputFile=c:\batch_bo_rep
set NewExecutionDate=2005-05-1
if exist "%OutputFile%" del "%OutputFile%"
for /f "tokens=1,2*" %%a in ('type "%InputFile%"') do (
if /i "%%a %%b"=="Execution Date" (
>>"%OutputFile%" echo Execution Date ^(YYYY-MM-DD^) : =%NewExecutionDate%
) else (
>>"%OutputFile%" echo %%a %%b %%c
)
)
Now the code works fine. It actualy creates a new batch_bo_report_param file and replaces the Execution Date. This batch_bo_report_param.txt file is actually used to pass certain data to some other file. Anyway, I normally run another batch report (CTPD950.bat) which in turn gets its Execution date from the batch_bo_report_param.txt file.
The problem is, the CTPD950.bat file will not run when this new param file is created. So I tested it out by cutting the exact lines (posted right above) and pasted it in the new batch_bo_report_param.txt file and the report CTPD950 ran. The four lines that I cut and pasted from the old batch_bo_report_param.txt file to the new one are:
BOUSER=bouser
BOPASS=bouser
Execution Date (YYYY-MM-DD) : =2005-03-28
Execution Month (YYYY-MM) : =2005-03
Is there any possible way of doing like a vbCrLf for a DOS batch file? I suspect this may be the cause, but I am uncertain. There is something about these four line that is causing the CTPD950.bat report not to run when it reads the newly created batch_bo_report_param.txt
I really need help on this as I am totally out of ideas.
Thank You
ASKER
obda,
Yes, it is necessary to change the Execution Month as well. So, it is the Execution Date & Execution Month that needs to be changed.
I believe the lines that are causing the problem are:
BOUSER=bouser
BOPASS=bouser
Execution Date (YYYY-MM-DD) : =2005-03-28
Execution Month (YYYY-MM) : =2005-03
bopass does not contain any special characters. it is meant to be that way.
obda, in a Batch File, is there any command like VBS such as vbCrLf? I believe this puts the line on the left of the file. I am not sure if this removes any spaces from the left or not. Any idea?
Thank You.
Ben
Yes, it is necessary to change the Execution Month as well. So, it is the Execution Date & Execution Month that needs to be changed.
I believe the lines that are causing the problem are:
BOUSER=bouser
BOPASS=bouser
Execution Date (YYYY-MM-DD) : =2005-03-28
Execution Month (YYYY-MM) : =2005-03
bopass does not contain any special characters. it is meant to be that way.
obda, in a Batch File, is there any command like VBS such as vbCrLf? I believe this puts the line on the left of the file. I am not sure if this removes any spaces from the left or not. Any idea?
Thank You.
Ben
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry, typo in the "Execution Month" line.
Replace the percent signs in this line
if /i "%aaToken:~0,15%"=="Execut ion Month" (
with exclamation marks:
if /i "!aaToken:~0,15!"=="Execut ion Month" (
Replace the percent signs in this line
if /i "%aaToken:~0,15%"=="Execut
with exclamation marks:
if /i "!aaToken:~0,15!"=="Execut
Then can you post the lines that are *not* working (if necessary, replace spaces with underscores or tildes or whatever, so that they don't get lost)?
And another question: is especially the data in bopass indeed "bopass", or does this contain any special characters like <>|^%?