文章参照自:http://hi.baidu.com/yjwkq/blog/item/b5adc801ee94fdd4277fb5b7.html<wbr style="line-height:25px"><div style="line-height:25px">
<div style="line-height:25px">
<span style="line-height:25px">二.如何在批处理文件中使用参数</span>
</div>
<div style="line-height:25px">
<span style="color:#003366; line-height:25px">批处理中可以使用参数,一般从1%到 9%这九个,当有多个参数时需要用shift来移动,这种情况并不多见,我们就不考虑它了。</span>
</div>
<div style="line-height:25px">
<span style="line-height:25px">比如</span>:fomat.bat</div>
<div style="line-height:25px"><span style="color:#0000ff; line-height:25px">@echo off</span></div>
<div style="line-height:25px">
<span style="color:#0000ff; line-height:25px">if "</span><span style="color:#ff6600; line-height:25px">%1</span><span style="color:#0000ff; line-height:25px">"=="a" format a:</span>
</div>
<div style="line-height:25px"><span style="color:#0000ff; line-height:25px">:format</span></div>
<div style="line-height:25px"><span style="color:#0000ff; line-height:25px">@format a:/q/u/auotset</span></div>
<div style="line-height:25px"><span style="color:#0000ff; line-height:25px">@echo please insert another disk to driver A.</span></div>
<div style="line-height:25px"><span style="color:#0000ff; line-height:25px">@pause</span></div>
<div style="line-height:25px"><span style="color:#0000ff; line-height:25px">@goto fomat</span></div>
<div style="line-height:25px"><span style="color:#000080; line-height:25px">这个例子用于连续地格式化几张软盘,所以用的时候需在dos窗口输入fomat.bat a,呵呵,</span></div>
<div style="line-height:25px"><span style="color:#000080; line-height:25px">好像有点画蛇添足了~^_^</span></div>
<div style="line-height:25px"><span style="line-height:25px">三.组合命令(Compound Command)</span></div>
<div style="line-height:25px"><span style="line-height:25px">1.&</span></div>
<div style="line-height:25px"><span style="color:#993300; line-height:25px">Usage:第一条命令 & 第二条命令 [& 第三条命令...]</span></div>
<div style="line-height:25px">
<span style="color:#000080; line-height:25px">用这种方法可以同时执行多条命令,而不管命令是否执行成功</span>
</div>
<div style="line-height:25px">
<span style="line-height:25px">比如</span>:</div>
<div style="line-height:25px"><span style="color:#000080; line-height:25px">C:\>dir z: & dir c:\Ex4rch</span></div>
<div style="line-height:25px"><span style="line-height:25px">2.&&</span></div>
<div style="line-height:25px"><span style="color:#993300; line-height:25px">Usage:第一条命令 && 第二条命令 [&& 第三条命令...]</span></div>
<div style="line-height:25px">
<span style="color:#003366; line-height:25px">用这种方法可以同时执行多条命令,当碰到执行出错的命令后将不执行后面的命令,如果一直没有出错则一直执行完所有命令;</span>
</div>
<div style="line-height:25px">
<span style="line-height:25px">比如</span>:</div>
<div style="line-height:25px"><span style="color:#000080; line-height:25px">C:\>dir z: && dir c:\Ex4rch</span></div>
<div style="line-height:25px"><span style="line-height:25px">3.||</span></div>
<div style="line-height:25px"><span style="color:#993300; line-height:25px">Usage:第一条命令 || 第二条命令 [|| 第三条命令...]</span></div>
<div style="line-height:25px"><span style="color:#000080; line-height:25px">用这种方法可以同时执行多条命令,当碰到执行正确的命令后将不执行后面的命令,如果没有出现正确的命令则一直执行完所有命令。</span></div>
<div style="line-height:25px">
<span style="line-height:25px">比如</span>:</div>
<div style="line-height:25px"><span style="color:#000080; line-height:25px">C:\Ex4rch>dir sometips.gif || del sometips.gif</span></div>
<div style="line-height:25px"><span style="line-height:25px">四、管道命令</span></div>
<div style="line-height:25px">
<span style="line-height:25px">1.| 命令</span>
</div>
<div style="line-height:25px">Usage:第一条命令 | 第二条命令 [| 第三条命令...]</div>
<div style="line-height:25px">将第一条命令的结果作为第二条命令的参数来使用,记得在unix中这种方式很常见。</div>
<div style="line-height:25px">
<span style="line-height:25px">比如</span>:</div>
<div style="line-height:25px">time /t>>D:\IP.log</div>
<div style="line-height:25px">netstat -n -p tcp|find ":3389">>D:\IP.log</div>
<div style="line-height:25px">
<span style="line-height:25px">2.>、>>输出重定向命令</span>
</div>
<div style="line-height:25px"><span style="color:#003366; line-height:25px">将一条命令或某个程序输出结果的重定向到特定文件中, > 与 >>的区别在于,>会清除调原有文件中的内容后写入指定文件,而>>只会追加内容到指定文件中,而不会改动其中的内容。</span></div>
<div style="line-height:25px"><span style="line-height:25px">3.< 、>& 、<&</span></div>
<div style="line-height:25px">
<span style="line-height:25px"><</span><span style="color:#003366; line-height:25px">从文件中而不是从键盘中读入命令输入。</span>
</div>
<div style="line-height:25px">
<span style="line-height:25px">>&</span><span style="color:#003366; line-height:25px">将一个句柄的输出写入到另一个句柄的输入中。</span>
</div>
<div style="line-height:25px">
<span style="line-height:25px"><&</span><span style="color:#003366; line-height:25px">从一个句柄读取输入并将其写入到另一个句柄输出中。</span>
</div>
</div>
</wbr>