I’m trying to make a helpful batch file for work and for it, I’m trying to input notes/text to a .txt file via a variable. It works great with just entering text without spaces (ex: “test”), but once you type something with at least 1 space in it, the cmd closes out. (ex: “test test”) I can’t figure out why this is happening so I’m left with you guys here. Any/all help would be appreciated!
@echo off
color 9F
title Notes
CLS
del %UserProfile%\Documents\Notes.txt
echo Issue/Request: >> %UserProfile%\Documents\Notes.txt
:StartCallNotes
CLS
echo ================== Notes =================
type %UserProfile%\Documents\Notes.txt
echo ==========================================
set /p NotesEnter=Enter Notes:
set NewNote="%NotesEnter%"
if %NotesEnter% == CLS goTo :CLS
echo %NotesEnter% >> "%UserProfile%\Documents\Notes.txt"
goTo :StartCallNotes
:CLS
del %UserProfile%\Documents\Notes.txt
echo Issue/Request: >> "%UserProfile%\Documents\Notes.txt"
goTo :StartCallNotes
exit
I think the problem is when you compare the user’s input with CLS.
Try to put quotes in %NotesEnter% when compare the value like this :