jeudi 30 mai 2019

How to make a "type" command go >nul if "The system cannot find the file specifed"

So i have a testing batch file that i use 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 doesnt show "The system cannot find the file specified."

ive tried type A6Test.log &if %ERRORCODE%==1 >nul and type A6Test.log ^&if %ERRORCODE%==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 %ERRORCODE%==1 >nul to display nothing if the file didnt exist but it showed

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.```

Aucun commentaire:

Enregistrer un commentaire