[Solved] Start up program with variables in line

Post

Posted
Rating:
#1 (In Topic #587)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
 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.
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
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: -

Code (gambas)

  1. Args.Begin
  2.   sArgPattern = Args.Get("p", "pattern", "File pattern to search e.g.'*.jpg,*.jpeg'", "Pattern")
  3.   sArgSearch = Args.Get("s", "search", "Text to search for", "Search")
  4.   sArgFolder = Args.Get("f", "folder", "Folder to search e.g.'~/pictures'", "Folder")
  5.   bArgCase = Args.Has("i", "ignorecase", "Ignore the case when searching")
  6.   bArgRecursive = Args.Has("R", "recusive", "Search in the sub folders of 'Folder'")
  7.   Args.End
  8.  

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
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
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

Code (gambas)

  1.  
  2. If Args.Count > 1 Then
  3.  
  4.   If Lower(Args[1]) = "/fullscreen" Then Me.Fullscreen = True
  5.  
  6.  
  7.  

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
Online now: No Back to the top

Post

Posted
Rating:
#4
Enthusiast
AndyGable is in the usergroup ‘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

Code (gambas)

  1.  
  2. If Args.Count > 1 Then
  3.  
  4.   If Lower(Args[1]) = "/fullscreen" Then Me.Fullscreen = True
  5.  
  6.  
  7.  

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 :)
Online now: No Back to the top
1 guest and 0 members have just viewed this.