如何简化cmd终端中的重复命令?

时间:2019-05-17 04:31:05

标签: windows performance batch-file

我写了许多重复的命令行,例如下面的命令行,也许有人输入来简化命令?尽可能简单。

@echo off
:stro
cls
echo. 
echo    Enter you term:
echo    ++++++++++++++++++++++
echo    1) Command Prompt (CMD)
echo    2) Power Shell
echo    3) Exit
echo.   
set /p kod=
if %kod% == 1 goto cmde
if %kod% == 2 goto pwsl
if %kod% == 3 goto exitx  
:exitx
echo set speech = Wscript.CreateObject("SAPI.spVoice") >> "tuntu.vbs"
echo speech.speak "thank you for use me. i hope you have a nice day. bye bye" >> "tuntu.vbs"
attrib +h "tuntu.vbs"
start tuntu.vbs
pause
attrib -h "tuntu.vbs"
del tuntu.vbs
exit
:cmde
start cmd
echo set speech = Wscript.CreateObject("SAPI.spVoice") >> "tuntu.vbs"
echo speech.speak "you choice is number %kod% and you open command prompt CMD"  >> "tuntu.vbs"
attrib +h "tuntu.vbs"
start tuntu.vbs
pause
attrib -h "tuntu.vbs"
del tuntu.vbs
goto stro
:pwsl
start powershell
echo set speech = Wscript.CreateObject("SAPI.spVoice") >> "tuntu.vbs"
echo speech.speak "you choice is number %kod% and you open Power shell"  >> "tuntu.vbs"
attrib +h "tuntu.vbs"
start tuntu.vbs
pause
attrib -h "tuntu.vbs"
del tuntu.vbs
goto stro

然后我想要一个简单的命令行,不包含重复无聊的句子。谢谢您的帮助

1 个答案:

答案 0 :(得分:0)

仅生成一次vbs脚本(使用参数而不是对文本进行硬编码):

您的代码然后缩短为:

@echo off

(echo set speech = Wscript.CreateObject("SAPI.spVoice"^)
echo speech.speak WScript.Arguments(0^))>"speak.vbs"
attrib +h speak.vbs
set "say=cscript /nologo speak.vbs"

:stro
cls
echo. 
echo    Enter you term:
echo    ++++++++++++++++++++++
echo    1) Command Prompt (CMD)
echo    2) Power Shell
echo    3) Exit
echo.   

choice /c 123
set kod=%errorlevel%
goto :label%kod%

:label3
%say% "thank you for using me. i hope you have a nice day. bye bye"
exit /b

:label1
start cmd
%say% "your choice is number %kod% and you open command prompt CMD"  
goto stro

:label2
start powershell
%say% "your choice is number %kod% and you open Power shell"
goto stro

我也将您的set /p替换为choice,因为choice处理用户输入并防止输入无效。