Batch file Programming (3)

Batch file Programming ကုိဆက္ေလ့လာၾကည့္ၾကမယ္။ အရင္တုန္းက ပုိ႕စ္ေတြမွာ output ကိုအဓိက ထားၿပီး ေရးထားပါတယ္။ အခု Process ပိုင္းကိုသြားၾကရေအာင္။ Process မွာ နိဒါန္းအေနနဲ႕ Labelling System ကေနစၾကမယ္။ Batch file Programming မွာ Looping ဆိုတာမရွိပါဘူး ဒီေတာ့ Looping အစား Labelling စနစ္ကို အသံုးျပဳထားပါတယ္။ ေအာက္က Code ကုိစမ္းၾကည့္လိုက္ပါဦး။ batch file ဘယ္လို run မလဲဆိုတာေတာ့ (1) နဲ႕ (2) မွာ ေျပာၿပီးသားျဖစ္ပါတယ္။ Code ကုိစမ္းၿပီးရင္ စက္ကုိ restart ခ်လိုက္ဦးေနာ္။ Looping ကဘယ္မွာဆံုးမလဲ ထည့္မထားလို႕ ေတာက္ေလွ်ာက္ run ေနမွာမုိ႕လို႕ပါ။

@echo off
:A
msg * This is testing for labelling system
goto A

:A ဆိုတာကေတာ့ သူ႕ေနာက္မွ ေရးမယ့္ instruction ေတြအတြက္ Label ေပးလိုက္တာပါ နာမည္ေပးတယ္ေပါ့။ msg * This is testing for labelling system နဲ႕ goto A ကို A လို႕နာမည္ေပးထားတာပါ goto A ဆိုတာကေတာ့ ခုနက A လုိ႕နာမည္ေပးထားတဲ့ Instruction ေတြကိုျပန္အလုပ္လုပ္ခိုင္းတာေပါ့ ဒီလိုနဲ႕ အဆံုးမရွိ အလုပ္လုပ္ေနတာကို looping သေဘာမ်ိဳးအသံုးျပဳထားတာပါ။ Forum ေတြမွာေတြ႕ေနက်ျဖစ္တဲ့ Virus ဆန္ဆန္ Batch file Programming ေလးေတြကိုေလ့လာၾကည့္ပါဦး။

@echo off
:A
start command
start firefox
start notepad
start explorer
goto A

ဒီ Code ကလဲ ဒီအတိုင္းပါပဲ။ start command ကေန goto A အထိကို A လို႕ Label ထုိးထားပါတယ္။ goto A ကေတာ့ အေပၚကေန ျပန္စခိုင္းတာပါပဲ ဒီလိုနဲ႕ Looping ကုိအဆံုးမသတ္ပဲထားေတာ့ ကုိယ့္စက္မွာ ေတာက္ေလွ်ာက္ run ေနေတာ့ ဗုိင္းရပ္စ္လို အေနွာင့္အယွက္ေပးသလိုျဖစ္သြားတာေပါ့။ ဒါကုိျပန္သတ္ခ်င္ရင္ restart ခ်လိုက္ပါ။ အကုန္ေပ်ာက္သြားပါလိမ့္မယ္။ ေနာက္ထပ္ေတာ့ မ run မိေစနဲ႕ေပါ့။ Looping ကိုအဆံုးသတ္ၿပီး သံုးခ်င္တယ္ဆိုရင္ေတာ့ ေနာက္ပုိ႕စ္တစ္ခုမွာ if else statement ေရးတဲ့အခါမွာ ထပ္ေရးေပးပါ့မယ္။ အခု Labelling ကုိဘယ္မွာထပ္သံုးလို႕ရေသးလဲ ေလ့လာၾကည့္မယ္။ Batch file Programming ရဲ႕အားနည္းခ်က္တစ္ခုကေတာ့ main flow မရွိတာပါပဲ။ ဥပမာ အားျဖင့္ C++ မွာဆုိရင္

void main(){

}

Java မွာဆိုရင္

public static void main(String[] args){

}

ဒီလိုမ်ိဳး Main Flow ေလးေတြရွိပါတယ္။ ဒါမွလဲ Program က run တဲ့အခါမွာ မ်ိဳးတူတဲ့ လုပ္ငန္းေတြကို function အေနနဲ႕ စုၿပီး main flow ကေန လွမ္းေခၚသံုးလုိ႕ အဆင္ေျပမွာေပါ့။ Batch file မွာကေတာ့ main flow မရွိပါဘူး။ ဒီေတာ့ label ကုိပဲသံုးၿပီးေတာ့ function အေနနဲ႕ သံုးၾကည့္ရေအာင္။ ဒီလိုသံုးမွလို႕ေတာ့ မဟုတ္ပါဘူး။ ကၽြန္ေတာ္ function အေနနဲ႕ သံုးၾကည့္႕မယ္ဆိုၿပီး စဥ္းစားမိတာပါ။ တစ္ျခားနည္းလမ္းရွိရင္လည္း Comment ေပးခဲ့နုိင္ပါတယ္။ ေအာက္က Code ကုိစမ္းၾကည့္လိုက္ပါဦး။

@echo off
echo This is main flow
goto newFunction
:main
echo This is return to main flow
pause

:newFunction
echo This is out of main flow
echo This is process by new function
goto main

ေဖာ္ျပထားတဲ့အတိုင္း This is out of main flow နဲ႕ This is process by new function ကို main flow ထဲမွာ ၀င္သံုးထားတာကိုေတြ႕ရပါမယ္။ function တစ္ခုေရးဖို႕အတြက္ function ေနာက္ဆံုးမွာ main ကုိျပန္သြားတဲ့ label သံုးဖို႕လိုပါလိမ့္မယ္။ ဒါကေတာ့ label ကုိသံုးၿပီး looping နဲ႕ function ကိုေရးထားတာျဖစ္ပါတယ္။

Facebook comments:

One Response

  1. mars says:

    ဆက်ရေးပါ… ကျနော်စောင့်ဖတ်နေပါတယ်…. တော်ကြာ comment မရှိလို့ဆိုပြီးရေးတာ မရပ်လိုက်ပါနဲ့… ကျေးဇူးတင်ပါတယ်…

Leave a comment


*