[Solved] Start up program with variables in line
Posted
#1
(In Topic #587)
Enthusiast

Does anyone have any guides on how I can send commands to my application when it starts up from the command line?
I mean for example
I want to run my program like this ./NPoS.gambas /Fullscreen
and when the program starts the app would read in the /Fullscreen and perform a action (maximize the form for example)
Hopefully I have explained myself here.
Posted
Guru

Code (gambas)
- Args.Begin
- sArgPattern = Args.Get("p", "pattern", "File pattern to search e.g.'*.jpg,*.jpeg'", "Pattern")
- sArgSearch = Args.Get("s", "search", "Text to search for", "Search")
- sArgFolder = Args.Get("f", "folder", "Folder to search e.g.'~/pictures'", "Folder")
- bArgCase = Args.Has("i", "ignorecase", "Ignore the case when searching")
- bArgRecursive = Args.Has("R", "recusive", "Search in the sub folders of 'Folder'")
- Args.End
You can then type on the Comman Line ./MyProg.gambas –help to get this: -
Code
Usage: InFile <options> <arguments>
Options:
-p --pattern <Pattern> File pattern to search e.g.'*.jpg,*.jpeg'
-s --search <Search> Text to search for
-f --folder <Folder> Folder to search e.g.'~/pictures'
-i --ignorecase <IgnoreCase> Ignore the case when searching
-R --recusive <Recursive> Search in the sub folders of 'Folder'
-V --version Display version
-h --help Display this help
Posted
Guru

Args[0] is always the calling application path/name "./NPoS.gambas"
Args[1] will be "/fullscreen" with your command example
the above method Cogier mentioned is better and has the advantage of automatically supplying the -h –help arg (and -V –version)
/comp/gb/args - Gambas Documentation (normal Args functions without adding gb.args)
/comp/gb.args/args - Gambas Documentation (gb.args functions)
Bruce
Posted
Enthusiast

BruceSteers said
without adding gb.args you can just check the Args[] array.
Args[0] is always the calling application path/name "./NPoS.gambas"
Args[1] will be "/fullscreen" with your command example
the above method Cogier mentioned is better and has the advantage of automatically supplying the -h –help arg (and -V –version)
/comp/gb/args - Gambas Documentation (normal Args functions without adding gb.args)
/comp/gb.args/args - Gambas Documentation (gb.args functions)
Bruce
Thanks for the information Bruce
1 guest and 0 members have just viewed this.



