home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.msdos.batch      Fun with MS-DOS batch files      42,547 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 41,773 of 42,547   
   Herbert Kleebauer to Anton Shepelev   
   Re: A failed output redirection does not   
   11 Nov 19 16:26:44   
   
   From: klee@unibwm.de   
      
   On 11.11.2019 14:42, Anton Shepelev wrote:   
      
   > I  can't seem to intercept an error while writing to   
   > a file at an invalid path:   
   >   
   > @echo off   
   > type a > C:\NOSUCHNDIR   est.txt   
   > IF ERRORLEVEL 1 goto ERROR   
   > echo All is well.   
   > goto END   
   > :ERROR   
   > echo Error detected.   
   > :END   
   >   
   > The script above writes:   
   >   
   > The system cannot find the path specified.   
   > All is well.   
   >   
   > C:\NOSUCHNDIR does not exist.  How can  I  test  the   
   > success of an output redirection?   
      
   type resets the errorlevel to 0 on success, so set it   
   to 1 before you execute type.   
      
   @echo off   
   call :set_err 1   
   echo test>a   
      
   type a > C:\NOSUCHNDIR\est.txt   
   IF ERRORLEVEL 1 goto ERROR   
   echo All is well.   
   goto END   
   :ERROR   
   echo Error detected.   
   :END   
      
   goto :eof   
      
   :set_err   
   exit /b %1   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca