S
Scott Bass
Guest
Hi,
I'm not sure this is the correct newsgroup - if not, can you please suggest
the appropriate one for a DOS batch question? Thanks...
I'd love to code my problem in VBS, PowerShell, Perl, Python, Ruby, ...
anything but DOS. Since I can't, here's my problem: (Note: I can't
install ANY additional s/w on the end user's machines and can't use VBS)
I've got a config file for an application that looks like:
-log "C:\Some\Path To\My Config\File\config.cfg"
I have to parse this file, extracting the value for the logs location into a
variable, in order to search the generated logs after the application
executes. The problem comes from the spaces in the file path.
I've got this code (with lots of debugging stub statements):
setlocal
FOR /F "usebackq tokens=2-5* delims= " %%a IN (`findstr /i /c:-log
"%config%"`) DO (
echo A %%a
echo B %%b
echo C %%c
echo D %%d
echo E %%e
if defined A echo A IS DEFINED
if defined B echo B IS DEFINED
if defined C echo C IS DEFINED
if defined D echo D IS DEFINED
if defined E echo E IS DEFINED
if not dummy==dummy%%a echo A IS NOT BLANK
if not dummy==dummy%%b echo B IS NOT BLANK
if not dummy==dummy%%c echo C IS NOT BLANK
if not dummy==dummy%%d echo D IS NOT BLANK
if not dummy==dummy%%e echo E IS NOT BLANK
if not dummy==dummy%%a set logs=%%a
if not dummy==dummy%%b set logs=%%logs %%b
if not dummy==dummy%%c set logs=%%logs %%c
if not dummy==dummy%%d set logs=%%logs %%d
if not dummy==dummy%%e set logs=%%logs %%e
echo %%logs
)
echo %%logs
It's not ideal, since I could (in theory) have a path with more than 5 space
separated tokens. But not likely, so I can live with this. I have a
feeling the problem could be due to immediate vs. delayed variable
resolution. And I may be using %%var vs. %var% incorrectly.
Ideally, I'd like to retrieve the line from the log, and do a search and
replace on "-log" (s/-log//g in say Perl or vi on Unix). But I can't see
how to do this in a DOS batch file. If there is a way to do a search and
replace in DOS OOTB, that would be great.
Any ideas how to parse the above to return the results equivalent to:
set logs="C:\Some\Path To\My Config\File\config.cfg"
Thanks,
Scott
I'm not sure this is the correct newsgroup - if not, can you please suggest
the appropriate one for a DOS batch question? Thanks...
I'd love to code my problem in VBS, PowerShell, Perl, Python, Ruby, ...
anything but DOS. Since I can't, here's my problem: (Note: I can't
install ANY additional s/w on the end user's machines and can't use VBS)
I've got a config file for an application that looks like:
-log "C:\Some\Path To\My Config\File\config.cfg"
I have to parse this file, extracting the value for the logs location into a
variable, in order to search the generated logs after the application
executes. The problem comes from the spaces in the file path.
I've got this code (with lots of debugging stub statements):
setlocal
FOR /F "usebackq tokens=2-5* delims= " %%a IN (`findstr /i /c:-log
"%config%"`) DO (
echo A %%a
echo B %%b
echo C %%c
echo D %%d
echo E %%e
if defined A echo A IS DEFINED
if defined B echo B IS DEFINED
if defined C echo C IS DEFINED
if defined D echo D IS DEFINED
if defined E echo E IS DEFINED
if not dummy==dummy%%a echo A IS NOT BLANK
if not dummy==dummy%%b echo B IS NOT BLANK
if not dummy==dummy%%c echo C IS NOT BLANK
if not dummy==dummy%%d echo D IS NOT BLANK
if not dummy==dummy%%e echo E IS NOT BLANK
if not dummy==dummy%%a set logs=%%a
if not dummy==dummy%%b set logs=%%logs %%b
if not dummy==dummy%%c set logs=%%logs %%c
if not dummy==dummy%%d set logs=%%logs %%d
if not dummy==dummy%%e set logs=%%logs %%e
echo %%logs
)
echo %%logs
It's not ideal, since I could (in theory) have a path with more than 5 space
separated tokens. But not likely, so I can live with this. I have a
feeling the problem could be due to immediate vs. delayed variable
resolution. And I may be using %%var vs. %var% incorrectly.
Ideally, I'd like to retrieve the line from the log, and do a search and
replace on "-log" (s/-log//g in say Perl or vi on Unix). But I can't see
how to do this in a DOS batch file. If there is a way to do a search and
replace in DOS OOTB, that would be great.
Any ideas how to parse the above to return the results equivalent to:
set logs="C:\Some\Path To\My Config\File\config.cfg"
Thanks,
Scott