简体   繁体   English

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

[英]Batch File Issue - Save Input To Text With Spaces

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. 我试图制作一个有用的批处理文件,为此,我试图通过一个变量将注释/文本输入到.txt文件中。 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. 只需输入不带空格的文本(例如:“ test”),它就可以很好地工作,但是一旦键入至少带1个空格的内容,cmd就会关闭。 (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. 我认为问题是当您将用户的输入与CLS进行比较时。 Try to put quotes in %NotesEnter% when compare the value like this : 比较如下所示的值时,尝试在%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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM