Search code examples
windowsbatch-fileechoerrorlevel

echoing (creating) an error log file


I have the following lines commands:

if %errorlevel% equ 1 (

                   set/a error=1
                   if not exist "error.log" echo. > "error.log"
                   echo the procedure has got an error >> "error.log" 
                   echo. >> "error.log
                  )

but like this I obtain the message that the file is being processed by another process.

There is maybe another way to create the file if not exists instead of using Echo.


Solution

  • You can create the file with

    copy NUL error.log
    

    However, I doubt that echo is your problem. More likely is that the file already exists and you have it opened in a text editor (or viewer) that locks the file.