Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File 批处理文件问题-将输入保存为带空格的文本_File_Variables_Input_Batch File_Space - Fatal编程技术网

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

File 批处理文件问题-将输入保存为带空格的文本,file,variables,input,batch-file,space,File,Variables,Input,Batch File,Space,我试图为工作创建一个有用的批处理文件,为此,我试图通过一个变量将notes/text输入到一个.txt文件中。它只需输入不带空格的文本(例如:“test”)就可以很好地工作,但一旦您输入的内容中至少有1个空格,cmd就会关闭。(例如:“测试”)我不明白为什么会发生这种情况,所以我只能和你们在一起了。任何/所有帮助都将不胜感激 @echo off color 9F title Notes CLS del %UserProfile%\Documents\Notes.txt echo Issue/

我试图为工作创建一个有用的批处理文件,为此,我试图通过一个变量将notes/text输入到一个.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

如果值包含空格,如何输入该值?“测试测试”或只是测试测试(不带引号)?不带引号。但是,如果您在其中的任何位置输入引号,它也会关闭。提示:如果您想找到导致错误的代码,只需在@echo离线时注释。:)哈哈,谢谢。另外,如何向文本文件添加空白?按enter键将显示“Echo is off”,如果我键入test并继续按enter键,它将重复最后一条消息。我想,如果你按enter键,在键入内容之前,这可能会有帮助。它会留下一个空白,后跟“Echo is off”:如果未定义,则返回NotesEnter Echo.>>%UserProfile%\Desktop\Notes.txt太棒了!再次感谢!:)如果我能再重复一遍,我会的。哈哈