簡體   English   中英

批處理文件問題-使用空格將輸入保存到文本

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM