我正在将自定义命令添加到 CMD。现在我有下面的代码:
@echo off
:takeinput
::Set input to blank to prevent commands from executing even if nothing is entered
set input=
echo.
set /p input=%cd%^>
::echo 0 here to check for errors
echo 0
call :emptycheck %input%
:emptycheck
::echo 1 here to check for errors
echo 1
::Go back to :takeinput if user entered nothing
if "%1"=="" goto takeinput
::Continue...
call :detect %input%
:detect
::echo 2 here to check for errors
echo 2
::Check if user entered a custom command or a normal command
if /i "%1"=="someCustomCommands" call :loop %input%
if /i "%1"=="someCustomCommands1" call :loop1 %input%
if /i "%1"=="someCustomCommands2" call :loop2 %input%
::echo 3 here to check for errors
echo 3
::If user enntered a normal command, execute it as normal
%input%
goto takeinput
:loop
::Custom command functions.....
:loop1
::Custom command functions.....
:loop2
::Custom command functions.....
到目前为止,一切都运行良好,甚至是我制作的自定义命令。但是每当我尝试将输出记录到文本文件中时,例如
echo hi >text.txt
,它总是会导致:
0
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
(“该进程无法访问...”重复2次)
在错误代码之后,实际上会出现一个文本文件,但其内容是“C:\Users\Administrator\Desktop^>”(即 :takeinput 循环中的 %cd%)
似乎永远不会回到 :takeinput 循环,因为屏幕上没有显示目录,只有闪烁的光标。并且批处理文件也停止工作。
“0”表示问题出在
call :emptycheck %input%
命令
有人可以告诉我我在这里做错了什么吗?我是批处理新手,正在尝试从错误中学习。
提前谢谢您。