我正在尝试为工作创建一个有用的批处理文件,为此,我正在尝试通过变量将注释/文本输入到.txt文件中。只需输入没有空格的文本(ex:“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
答案 0 :(得分: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