I have been testing a batch file, that I used to see if my ideas work in batch. I had an idea to make a logging system, but if the file cant be found it doesn't show "The system cannot find the file specified."
I've tried type A6Test.log &if %ERRORLEVEL%==1 >nul
and type A6Test.log ^&if %ERRORLEVEL%==1 >nul
but the first just exited the file and the second displayed:
The system cannot find the file specified. Error occurred while processing: A6Test.log. The system cannot find the file specified. Error occurred while processing: &If. The system cannot find the file specified. Error occurred while processing: 1.
All you need to recreate this is below.
@echo off
:A6
cls
echo Log file:
type "A6Test.log" ::Problem
set /p Log=
echo %Log%>>"A6Test.log" ::this echos %log% into the log file, "A6Test.log"
goto A6
I expected type "A6Test.log" ^&if %ERRORLEVEL%==1 >nul
to display nothing if the file didnt exist but it showed:
The system cannot find the file specified. Error occurred while processing: A6Test.log. The system cannot find the file specified. Error occurred while processing: &If. The system cannot find the file specified. Error occurred while processing: 1.