0

我正在尝试为工作制作一个有用的批处理文件,为此,我正在尝试通过变量将注释/文本输入到 .txt 文件中。它非常适合只输入不带空格的文本(例如:“test”),但是一旦你输入了至少有 1 个空格的内容,cmd 就会关闭。(例如:“测试测试”)我不知道为什么会发生这种情况,所以我留在这里和你们在一起。任何/所有帮助将不胜感激!

@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
4

1 回答 1

0

我认为问题在于当您将用户的输入与 CLS 进行比较时。在比较这样的值时,尝试在 %NotesEnter% 中加上引号:

@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%"

REM if user doesn't input the value echo a new line
if "%NotesEnter%" == "" echo. >> "%UserProfile%\Documents\Notes.txt"

if "%NotesEnter%" == CLS goTo :CLS

if NOT "%NotesEnter%" == "" echo %NotesEnter% >> "%UserProfile%\Documents\Notes.txt"

REM reset the variable value
set NotesEnter=

goTo :StartCallNotes

:CLS
del %UserProfile%\Documents\Notes.txt
echo Issue/Request: >> "%UserProfile%\Documents\Notes.txt"
goTo :StartCallNotes

exit
于 2013-01-26T07:38:28.843 回答