本文主要是介绍.bat文件中start, pause,goto以及rem的用法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
- @ echo off
- start calc
- start calc
- start calc
@ echo off
start calc
start calc
start calc
结果,连续启动了三个计算器。
另外,start也可以用来打开一个文件夹,如:
- @ echo off
- md 1
- start 1
@ echo off
md 1
start 1
当然,start也可以打开某一文件,如:
- @ echo off
- echo hello world > 1.txt
- start 1.txt
@ echo off
echo hello world > 1.txt
start 1.txt
我发现, start可以可开word文件(当然,你的电脑需要有word软件),可见,start就相当于双击文件。
pause的作用很简单,就是暂停执行,如:
- @ echo off
- pause
- start calc
- pause
- start calc
- pause
- start calc
- pause
@ echo off
pause
start calc
pause
start calc
pause
start calc
pause
接下来,我们看看goto
- @ echo off
- goto label
- dir
- :label
- md 1
@ echo off
goto label
dir
:label
md 1
在这里,dir没有执行, 跟C语言中的goto和棋相似啊,只是:符号在label之前而已。下面,我们写一个有趣的goto:
- @ echo off
- :labelx
- goto labely
- :labely
- dir
- goto labelx
@ echo off
:labelx
goto labely:labely
dir
goto labelx
最后,我们来看看rem(remark)的用法,其实rem就是一个注释,主要是使看.bat文件命令的人阅读方便,如下:
- @ echo off
- rem 开始
- rem echo 开始
- echo 开始
@ echo off
rem 开始
rem echo 开始
echo 开始
需要注意的是:在用rem的时候,要将echo设为off的状态,否则,该命令虽然被注释,系统不会执行,但仍然会回显(当然啦,你也可以用@)。而且,在用rem注释的时候,rem必须另外单独占一行,和c++中的注释//不一样。
这篇关于.bat文件中start, pause,goto以及rem的用法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!