1

First time posting here. I'm writing a DOS batch script to automate the process of archiving Oracle tables. The archive tool requires a parameter file with tags that need to be populated at run-time. I am using the following logic, trying 2 different methods to catch the error, but when redirecting to a bad path, the error is not being caught. Is there an alternative to ECHO, or an alternate way to detect this write error? Or any other ideas? Thanks much!
-Greg

@ECHO OFF
FOR /F %%G IN (O:\tmp\infile.txt) DO (
    ...
    ...
   ECHO TABLE=%%G    > P:\BADPATH\MYOUTFILE1.TXT
   IF %ERRORLEVEL% NEQ 0 GOTO END
    ...
   ECHO TABLE=%%G    > P:\BADPATH\MYOUTFILE2.TXT
   IF ERRORLEVEL 1 GOTO END
    ...
    ...
 )

:END
IF %ERRORLEVEL% NEQ 0 ECHO FAILED! 
ECHO EXITING
  • have a look at this question: http://stackoverflow.com/questions/10354016/file-redirection-in-windows-and-errorlevel – wmz Mar 09 '13 at 21:31
  • Hello wmz, Thanks much for your response. That is an interesting post. I need a bit of time to digest it and test it. – user2151990 Mar 10 '13 at 12:53

1 Answers1

0

Not sure if I understand correctly, but it sounds like you want to check if a file/folder exists first. If so:

IF EXIST P:\BADPATH\ goto notexist else goto exist
:notexist
echo Doesn't exist.
:exist
echo It exists!

Or use standard () tags to contain code within.

Glenn
  • 541
  • 1
  • 6
  • 18
  • Hello. Thanks much Glenn for your quick response. That is a great suggestion - I did not know about EXIST. But I could not understand why ERRORLEVEL works for other commands, but not for ECHO. – user2151990 Mar 09 '13 at 18:28
  • I'm not sure on that one. Not used errorlevel much, I usually just pre-check for possible errors and act accordingly. Let me know if it works. – Glenn Mar 09 '13 at 18:32