我们先来看start, 其实start就是启动,我以前经常用matlab中的system来启动.exe文件,下面我们用start来启动.exe, .bat文件内容如下:
- @ echo off
- start calc
- start calc
- start calc
结果,连续启动了三个计算器。
另外,start也可以用来打开一个文件夹,如:
当然,start也可以打开某一文件,如:
- @ 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
接下来,我们看看goto
- @ echo off
- goto label
- dir
- :label
- md 1
在这里,dir没有执行, 跟C语言中的goto和棋相似啊,只是:符号在label之前而已。下面,我们写一个有趣的goto:
- @ echo off
- :labelx
- goto labely
-
- :labely
- dir
- goto labelx
最后,我们来看看rem(remark)的用法,其实rem就是一个注释,主要是使看.bat文件命令的人阅读方便,如下:
- @ echo off
- rem 开始
- rem echo 开始
- echo 开始
需要注意的是:在用rem的时候,要将echo设为off的状态,否则,该命令虽然被注释,系统不会执行,但仍然会回显(当然啦,你也可以用@)。而且,在用rem注释的时候,rem必须另外单独占一行,和c++中的注释//不一样。
|