2017-05-05 245 views
-1

我在写一个windows脚本,询问用户的名字和用户名。 当我在cmd中运行它时,会返回错误消息“无法找到指定的文件”。找不到指定的文件错误

下面是代码:

@echo off 

title User Records System 
ECHO Welcome to the User Records System 

SET /P <name>=[Please enter you full name.] 
REM if %name% = nul goto :label6 
pause 

SET /P <uName>=[Please enter your username.] 
REM if %uName% = nul goto :label10 
pause 

ECHO %date%_%time% %name% >>C:\user_records.txt 
ECHO %date%_%time% %uName% >>C:\user_records.txt 
ECHO %date%_%time% %time% >>C:\user_records.txt 
pause 

我知道的修复是非常明显的,我只是很新。 此外,如果您有任何其他建议的改进,请让我知道。 谢谢。

回答

1

在批处理文件中的角括号是重定向操作符,所以

  v.................................... write to file "=[Pl..." 
SET /P <name>=[Please enter you full name.] 
     ^......................................... read from file "name" 

你应该使用类似

SET "name=" 
SET /p "name=[Please enter you full name.]" 
if not defined name goto :label6 

SET "uName=" 
SET /P "uName=[Please enter your username.]" 
if not defined uName goto :label10 
+0

太棒了谢谢你! –

0

你也只能做到这一点

set /p name= "[Please enter your full name.]" 
if not defined name goto :label6 
pause 

set /p uName= "[Please enter your username.]" 
if not defined uName goto :label10 
pause 

这样,你必须键入“设置”一次。只是一点捷径。仅供参考,我建议在等号后面加上空格。

相关问题