atvaxtr Posted December 21, 2017 Share Posted December 21, 2017 (edited) Hey guys, I am coding and testing a very simple program, which can be used/started with the commandline / .bat-File. Like this: start myprog.exe "subapp1" "parameter1" "parameter2" start myprog.exe "subapp2" "parameter1" "parameter2" start myprog.exe "volumeset" "parameter1" start myprog.exe "disablewifi" "parameter1" The program has, lets say over 300 "subapps" What is the best way, to organize the subapps? I want to archive best perfomance (less loading time, less CPU-usage, RAM-usage... I thought about two solutions: either this: simply use "IF" to route to the subapps But I'm afraid, that the program then does "300+" If checks, everytime the program is started... IF $CMDLINE[1] = "subapp1" THEN ;do something with $CMDLINE[2] $CMDLINE[3] ENDIF IF $CMDLINE[1] = "subapp2" THEN ;do something with $CMDLINE[2] $CMDLINE[3] ENDIF IF $CMDLINE[1] = "subapp3" THEN ;do something with $CMDLINE[2] $CMDLINE[3] ENDIF or: Use Functions to route to the subapps. In this case, I'm afraid the program loads 300+ functions to the memory, everytime the program is started Dim $PAR__MERGE FOR $A = 2 To $CMDLINE[0] $PAR__MERGE = $PAR__MERGE & ";" & $CMDLINE[$A] NEXT CALL("__" & $CMDLINE[1],StringTrimLeft($PAR__MERGE,1)) Func __subapp1($PAR__MERGE) $PARSUB = StringSplit($PAR__MERGE, ";", 1) ;do something with $vPARSUB[1] $vPARSUB[2] EndFunc Func __subapp2($PAR__MERGE) $PARSUB = StringSplit($PAR__MERGE, ";", 1) ;do something with $vPARSUB[1] $vPARSUB[2] EndFunc Func __subapp3($PAR__MERGE) $PARSUB = StringSplit($PAR__MERGE, ";", 1) ;do something with $vPARSUB[1] $vPARSUB[2] EndFunc Are there better, smarter solutions? I hope you guys have some good advices for me. Thank you in advance for your help Edited December 21, 2017 by atvaxtr Link to comment Share on other sites More sharing options...
careca Posted December 21, 2017 Share Posted December 21, 2017 (edited) You can skip some checks, if you do something like: If $CmdLine[0] = 2 Then ;2 parameters If $CmdLine[1] = 'subapp1' Then ;sfadggsdg ElseIf $CmdLine[1] = 'subapp2' Then ;asfsgrhrh EndIf EndIf If $CmdLine[0] = 1 Then ;1 parameter If $CmdLine[1] = 'subapp3' Then ;sfadggsdg ElseIf $CmdLine[1] = 'subapp4' Then ;asfsgrhrh EndIf EndIf because you mention you may have sometimes 1 parameter, other times 2, or 3, this way you can avoid a bunch of checks. Edited December 21, 2017 by careca Earthshine 1 Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
Earthshine Posted December 21, 2017 Share Posted December 21, 2017 (edited) i used to be the king of command line apps written in C so they were .com files... lol, anyway, in the end, I built an argument parser that did things careca mentioned above. you could even put stuff in any order and I would figure it out. my users loved my utilities. I wish I could find that code. Now I need to re-create it in C# :-( time to read I guess: https://www.google.com/search?q=best+practice+for+command+line+argument+processing&oq=best+practice+for+command+line+argument+processing&aqs=chrome..69i57.10716j0j7&sourceid=chrome&ie=UTF-8 this is a GREAT discussion on the topic https://softwareengineering.stackexchange.com/questions/307467/what-are-good-habits-for-designing-command-line-arguments?newreg=498a20a7c7e64905af4bf2dd02422881 Edited December 21, 2017 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Earthshine Posted December 21, 2017 Share Posted December 21, 2017 oh goody! in C# Mono.Options namespace has me covered! that's why I love C# so much. so much support, no wasting of time. My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Skysnake Posted December 22, 2017 Share Posted December 22, 2017 @Earthshine, May I be so bold as to request you post C# and equivalent AutoIt examples here so we can all benefit from your skill and wisdom? Skysnake Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
Earthshine Posted December 22, 2017 Share Posted December 22, 2017 (edited) Well I would have to write the auto IT stuff plus argument checking in C in C sharp is pretty different than autoit If you look at the link that I posted they basically spell it out there exactly. I’ll post more stuff later from those articles for instance, reading the Stack Exchange thread you will see TONS of great stuff in the answers. I try to do all the standard stuff, supporting -h -help, etc and check for nulls, etc... but also this /flag and /flag:value you pass a flag and it does stuff. should the flag be a variable or property you use the /flag:value so see, you can pass in any order that way, such as /InstallDir:"C:\PoopInstall\Dir" or something like that. makes parsing easy. as for the best processing order in autoit, well, you will have to test and figure that one out. I'm not writing this... lol, if I do an Console app it's C# (which anyone can do with just Windows 10 installed and NOTHING else! MSBUILD is your friend. LOL) Edited December 22, 2017 by Earthshine My resources are limited. You must ask the right questions 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