DOS批处理简介(下)

文章参照自: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.&amp;</span></div> <div style="line-height:25px"><span style="color:#993300; line-height:25px">Usage:第一条命令 &amp; 第二条命令 [&amp; 第三条命令...]</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:\&gt;dir z: &amp; dir c:\Ex4rch</span></div> <div style="line-height:25px"><span style="line-height:25px">2.&amp;&amp;</span></div> <div style="line-height:25px"><span style="color:#993300; line-height:25px">Usage:第一条命令 &amp;&amp; 第二条命令 [&amp;&amp; 第三条命令...]</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:\&gt;dir z: &amp;&amp; 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&gt;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&gt;&gt;D:\IP.log</div> <div style="line-height:25px">netstat -n -p tcp|find ":3389"&gt;&gt;D:\IP.log</div> <div style="line-height:25px"> <span style="line-height:25px">2.&gt;、&gt;&gt;输出重定向命令</span> </div> <div style="line-height:25px"><span style="color:#003366; line-height:25px">将一条命令或某个程序输出结果的重定向到特定文件中, &gt; 与 &gt;&gt;的区别在于,&gt;会清除调原有文件中的内容后写入指定文件,而&gt;&gt;只会追加内容到指定文件中,而不会改动其中的内容。</span></div> <div style="line-height:25px"><span style="line-height:25px">3.&lt; 、&gt;&amp; 、&lt;&amp;</span></div> <div style="line-height:25px"> <span style="line-height:25px">&lt;</span><span style="color:#003366; line-height:25px">从文件中而不是从键盘中读入命令输入。</span> </div> <div style="line-height:25px"> <span style="line-height:25px">&gt;&amp;</span><span style="color:#003366; line-height:25px">将一个句柄的输出写入到另一个句柄的输入中。</span> </div> <div style="line-height:25px"> <span style="line-height:25px">&lt;&amp;</span><span style="color:#003366; line-height:25px">从一个句柄读取输入并将其写入到另一个句柄输出中。</span> </div> </div> </wbr>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值