Batch file doesn't process when executed, but does when pasted into command window

aburgard

Limp Gawd
Joined
Dec 28, 2005
Messages
357
I'm working with a batch file that doesn't process when executed, but does when pasted into command window:

Code:
SET directory=C:\Uwharrie
SET file=Limits.csv

FOR /F "tokens=1,2,3,4,5,6,7 delims=," %G IN (%directory%\%file%) DO (
IF "%H"=="00118" (ECHO %G,%H,%I,%J,%K,%L,%M >>%directory%\Limits_00118.csv) 
IF "%H"=="00196" (ECHO %G,%H,%I,%J,%K,%L,%M >>%directory%\Limits_00196.csv) 
IF "%H"=="00125" (ECHO %G,%H,%I,%J,%K,%L,%M >>%directory%\Limits_00125.csv))

When executed it spawns a window then closes the window with no output files. When pasted into a command window it creates 3 files as expected.

Any assistance is greatly appreciated!
 
add a pause at the end so that you can see any error messages that may get displayed.
 
You have to escape single percent signs with double percent signs. Any variable that starts (but not ends) with a single % needs to be escaped. In your example, %G needs to be %%G, %H needs to be %%H, etc.
 
Back
Top