[英]Batch File Issue - Save Input To Text With Spaces
我试图制作一个有用的批处理文件,为此,我试图通过一个变量将注释/文本输入到.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
我认为问题是当您将用户的输入与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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.