Dzwebs.Net

撰写电脑技术杂文十余年

批处理同时运行几行代码的两种方式

Admin | 2017-3-13 15:41:48 | 被阅次数 | 5483

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

  想让批处理同时运行几行代码,可以有如下的两种形式

  第一种形式:使用&

  语法:第一条命令 & 第二条命令 [& 第三条命令...]

  用这种方法可以同时执行多条命令,而不管命令是否执行成功

  举例如下

  C:\>dir z: & dir c:\Ex4rch

  The system cannot find the path specified.
  Volume in drive C has no label.
  Volume Serial Number is 0078-59FB
  Directory of c:\Ex4rch
  2002-05-14 23:51 <DIR> .
  2002-05-14 23:51 <DIR> ..
  2002-05-14 23:51 14 sometips.gif

  第二种形式:使用&&

  语法:第一条命令 && 第二条命令 [&& 第三条命令...]

  用这种方法可以同时执行多条命令,当碰到执行出错的命令后将不执行后面的命令,如果一直没有出错则一直执行完所有命令;

  举例如下:

  C:\>dir z: && dir c:\Ex4rch

  The system cannot find the path specified.

  C:\>dir c:\Ex4rch && dir z:

  Volume in drive C has no label.
  Volume Serial Number is 0078-59FB
  Directory of c:\Ex4rch
  2002-05-14 23:55 <DIR> .
  2002-05-14 23:55 <DIR> ..
  2002-05-14 23:55 14 sometips.gif
  1 File(s) 14 bytes
  2 Dir(s) 768,671,744 bytes free

  The system cannot find the path specified.

  在做备份的时候可能会用到这种命令会比较简单,如:

dir file://192.168.0.1/database/backup.mdb && copy file://192.168.0.1/database/backup.mdb E:\backup

  如果远程服务器上存在backup.mdb文件,就执行copy命令,若不存在该文件则不执行copy命令。这种用法可以替换IF exist了 :) 

  第三种形式:使用||

  语法:第一条命令 || 第二条命令 [|| 第三条命令...]

  用这种方法可以同时执行多条命令,当碰到执行正确的命令后将不执行后面的命令,如果没有出现正确的命令则一直执行完所有命令;

  举例如下:

  C:\Ex4rch>dir sometips.gif || del sometips.gif

  Volume in drive C has no label.
  Volume Serial Number is 0078-59FB
  Directory of C:\Ex4rch
  2002-05-14 23:55 14 sometips.gif
  1 File(s) 14 bytes
  0 Dir(s) 768,696,320 bytes free

  组合命令使用的例子:

  再举例:

  @copy trojan.exe \\%1\admin$\system32 && if not errorlevel 1 echo IP %1 USER %2 PASS %3 >>victim.txt

  No.4 

该杂文来自: 基础知识杂文

上一篇:FF浏览器输入网址后没有反映(按回车键没反映)

下一篇:批处理管道命令的使用

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计