请帮助cmd批处理文件

时间:2014-09-08 20:09:29

标签: batch-file input cmd

我是cmd命令的新手,我试图制作至少一个批处理文件,为我的女朋友打开3个不同的网站,所以我试过这个:

@echo off
title (something)
color 05
echo (welcome)
echo.
echo.
echo.
echo choose music
echo to listen to song one. press 1
echo to listen to song two. press 2
echo to listen to song three. press 3
set/p input= You choose:
if %input% == 1 goto Song one
:Song one
echo opening song one
start chrome "link1"
pause
:exit
echo choose music
echo to listen to song one. press 1
echo to listen to song two. press 2
echo to listen to song three. press 3
set/p input= You choose:
if %input% == 2 goto song two
:song two
echo opening song two
start chrome "link2"
pause
:exit
echo choose music
echo to listen to song one. press 1
echo to listen to song two. press 2
echo to listen to song three. press 3
set/p input= You choose:
if %input% == 3 goto Song one
:Song three
echo opening song three
start chrome "link3"
pause
:exit

并且输入似乎搞砸了,我可以键入W并且它将像1,2或3一样工作,其他问题是,它不会对应于数字,如果我想打开3并按3它打开1,然后再打2,然后3,在3 cmd崩溃后,任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分:0)

您的脚本存在许多问题。应该更像这样:

@echo off
cls
title (something)
color 05
echo (welcome)
echo.
echo.
echo.

:PickAgain
echo Choose music:
echo To listen to song one, press 1.
echo To listen to song two, press 2.
echo To listen to song three, press 3.
echo To quit, press 4.
set/p input= You choose:

if %input% == 1 goto Song1
if %input% == 2 goto Song2
if %input% == 3 goto Song3
if %input% == 4 goto Quit
goto PickAgain

:Song1
echo opening song one
start chrome "link1"
goto PickAgain

:Song2
echo opening song two
start chrome "link2"
goto PickAgain

:Song3
echo opening song three
start chrome "link3"
goto PickAgain

:Quit

答案 1 :(得分:0)

好的,我冒昧地让你的脚本更清洁,同时解决你的问题。

以下是新批处理文件的代码:

@echo off
Color 09
Title (Something)
Echo Welcome
:Start
Cls
Echo To listen to song 1, press 1.
Echo To listen to song 2, press 2.
Echo To listen to song 3, press 3.
Echo To quit, press 4.
Choice /c 1234 >nul
If %errorlevel%==1 start chrome.exe (Link1) & goto start
If %errorlevel%==2 start chrome.exe (Link2) & goto start
If %errorlevel%==3 start chrome.exe (Link3) & goto start
Exit

顺便说一句看起来像

的代码

'如果%errorlevel%== 1启动chrome.exe(链接)&转到开始'

应该在一条线上。 希望这有帮助!