批处理文件问题 - 将输入保存到带空格的文本



我正在尝试为工作制作一个有用的批处理文件,为此,我正在尝试通过变量将注释/文本输入到.txt文件中。它适用于只输入没有空格的文本(例如:"测试"),但是一旦您键入至少包含 1 个空格的内容,cmd 就会关闭。(例如:"测试测试")我不知道为什么会这样,所以我留在这里和你们在一起。任何/所有帮助将不胜感激!

@echo off
color 9F
title Notes
CLS
del %UserProfile%DocumentsNotes.txt
echo Issue/Request: >> %UserProfile%DocumentsNotes.txt
:StartCallNotes
CLS
echo ================== Notes =================
type %UserProfile%DocumentsNotes.txt
echo ==========================================
set /p NotesEnter=Enter Notes: 
set NewNote="%NotesEnter%"
if %NotesEnter% == CLS goTo :CLS
echo %NotesEnter% >> "%UserProfile%DocumentsNotes.txt"
goTo :StartCallNotes
:CLS
del %UserProfile%DocumentsNotes.txt
echo Issue/Request: >> "%UserProfile%DocumentsNotes.txt"
goTo :StartCallNotes
exit
我认为

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

@echo off
color 9F
title Notes
CLS
del %UserProfile%DocumentsNotes.txt
echo Issue/Request: >> %UserProfile%DocumentsNotes.txt
:StartCallNotes
CLS
echo ================== Notes =================
type %UserProfile%DocumentsNotes.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%DocumentsNotes.txt"
if "%NotesEnter%" == CLS goTo :CLS
if NOT "%NotesEnter%" == "" echo %NotesEnter% >> "%UserProfile%DocumentsNotes.txt"
REM reset the variable value
set NotesEnter=
goTo :StartCallNotes
:CLS
del %UserProfile%DocumentsNotes.txt
echo Issue/Request: >> "%UserProfile%DocumentsNotes.txt"
goTo :StartCallNotes
exit

相关内容

  • 没有找到相关文章

最新更新