MerkurAlex Posted January 28, 2009 Share Posted January 28, 2009 Yes its extremely simple but it works well and comes in handy A LOT. if $cmdline[0]<>0 then for $i=1 to $cmdline[0] Switch $cmdline[$i] case "/switch1";this is a simple switch that can set a variable or aynthing else you need it to in this case call a function dosomething() case "/switch2";this switch requires a value after it if $cmdline[0]=$i+1 or $cmdline[0]>$i+1 then msgbox("","","/switch2 = "&$cmdline[$i+1]) Else MsgBox(16,"Error","Error in the command line!") Exit EndIf EndSwitch Next EndIf func dosomething() msgbox("","","i did something!") endfunc A few batch lines to test with: sclss.exe /switch1 sclss.exe /switch2 sclss.exe /switch2 test sclss.exe /switch2 blahblah /switch1 the first will show a msgbox the second give you an error the third will give a different msgbox with the value and the fourth is a combination of both working. Have fun [quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote] Link to comment Share on other sites More sharing options...
BrettF Posted January 28, 2009 Share Posted January 28, 2009 Nice simple example: I hope you don't mind but I modified your code in one place... If $cmdline[0] <> 0 Then For $i = 1 To $cmdline[0] Switch $cmdline[$i] Case "/switch1";this is a simple switch that can set a variable or aynthing else you need it to in this case call a function dosomething() Case "/switch2";this switch requires a value after it If $cmdline[0] >= $i + 1 Then MsgBox("", "", "/switch2 = " & $cmdline[$i + 1]) Else MsgBox(16, "Error", "Error in the command line!") Exit EndIf EndSwitch Next EndIf Func dosomething() MsgBox("", "", "i did something!") EndFunc ;==>dosomething This is what I used to run it... $file = @ScriptDir & "\cmdlinetest.exe" RunWait ($file & " /switch1") RunWait ($file & " /switch2") RunWait ($file & " /switch2 test") RunWait ($file & " /switch2 blahblah /switch1") Thanks for sharing! Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now