Hi All,
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.
[Solved] Start up program with variables in line
-
- Posts: 363
- Joined: Wednesday 2nd December 2020 12:11am
- Location: Northampton, England
- Contact:
[Solved] Start up program with variables in line
Last edited by AndyGable on Tuesday 23rd February 2021 5:23pm, edited 1 time in total.
- cogier
- Site Admin
- Posts: 1126
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Start up program with variables in line
The Command Line Arguments can be picked up by the Args command. If you want to do this like the pros then look at the gb.args which allows you to do this: -
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: Select all
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
- BruceSteers
- Posts: 1575
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Start up program with variables in line
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
http://gambaswiki.org/wiki/comp/gb/args (normal Args functions without adding gb.args)
http://gambaswiki.org/wiki/comp/gb.args/args (gb.args functions)
Bruce
Args[0] is always the calling application path/name "./NPoS.gambas"
Args[1] will be "/fullscreen" with your command example
If Args.Count > 1 Then
If Lower(Args[1]) = "/fullscreen" Then Me.Fullscreen = True
Endif
the above method Cogier mentioned is better and has the advantage of automatically supplying the -h --help arg (and -V --version)http://gambaswiki.org/wiki/comp/gb/args (normal Args functions without adding gb.args)
http://gambaswiki.org/wiki/comp/gb.args/args (gb.args functions)
Bruce
If at first you don't succeed , try doing something differently.
BruceS
BruceS
-
- Posts: 363
- Joined: Wednesday 2nd December 2020 12:11am
- Location: Northampton, England
- Contact:
Re: Start up program with variables in line
Thanks for the information BruceBruceSteers wrote: ↑Thursday 18th February 2021 3:10pm 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)
If Args.Count > 1 Then If Lower(Args[1]) = "/fullscreen" Then Me.Fullscreen = True Endif
http://gambaswiki.org/wiki/comp/gb/args (normal Args functions without adding gb.args)
http://gambaswiki.org/wiki/comp/gb.args/args (gb.args functions)
Bruce