Gambas executable entry value

Post

Posted
Rating:
#1 (In Topic #1179)
Regular
bill-lancaster is in the usergroup ‘Regular’
I run a gambas executable from another gambas project by:-

Code

Exec ["/home/bill/GambasFolder/Executable/DocsViewer.gambas"]

How can I provide an entry value (a file name) to DocsViewer.gambas?
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’

bill-lancaster said

I run a gambas executable from another gambas project by:-

Code

Exec ["/home/bill/GambasFolder/Executable/DocsViewer.gambas"]

How can I provide an entry value (a file name) to DocsViewer.gambas?

Exec arguments are an array, additional parameters just need more strings.

Consider this terminal line…

gambas3 /path/myproject

simply..

Code (gambas)

  1. '
  2. Exec ["gambas3", "/path/myproject"]
  3. '
  4. 'or
  5. Shell "gambas3 /path/myproject"
  6.  

To provide environment variables use "With"

so terminal would be
env GB_GUI=gb.qt5 gambas3 /path/myproject

gambas Exec syntax….

Code (gambas)

  1. '
  2. Exec ["gambas3", "/path/myproject"] With ["GB_GUI=gb.qt5"]
  3. '
  4.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
bill-lancaster is in the usergroup ‘Regular’
Thanks Bruce,
Having trouble with syntax,

Code

  Print Exist(User.Home &/ "GambasFolder/Executable/Golf.gambas")
  Exec ["gambas3", "GambasFolder/Executable/Golf.gambas"]
The first line confirms that the file exists.
The second line produces an error:- "Cannot open a binary file"
Where am I going wrong?
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
Use absolute paths

Put User.Home in the exec too

Exec ["gambas3", User.Home &/ "GambasFolder/Executable/Golf.gambas"]

oops my mistake i see you are opening a .gambas file with the gambas3 IDE
open the parent folder instead

Exec ["gambas3", User.Home &/ "GambasFolder/Executable"]

or to run the application without a compiled executable try this..

Exec ["gbx3", User.Home &/ "GambasFolder/Executable"]

or to run the executable

Exec ["gbr3", User.Home &/ "GambasFolder/Executable/Golf.gambas"]

You'll want something like this though…

Code (gambas)

  1.  
  2. Exec ["/home/bill/GambasFolder/Executable/DocsViewer.gambas", "/path/to/thedoc/item.doc"]
  3.  
  4.  
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
Shell, shell, shell! Or maybe C shells big shells along the see-saw.
(I think I may have to have a little lie down now)
 ;)
b

Online now: No Back to the top

Post

Posted
Rating:
#6
Regular
bill-lancaster is in the usergroup ‘Regular’
Thanks again Bruce,

Code

Exec ["gbr3", "GambasFolder/Executable/DocsViewer.gambas"] With ["sTemp=XXX"]

opens "DocsViewer" OK but there is only one  args.count.

Shell "gbr3 ~/GambasFolder/Executable/DocsViewer.gambas sTemp=XXXX'"  works fine, args.count = 2.

BTW I extract the argument value with Split(Args[1], "=")[1] is there a better way?

Bill
Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’
"With" provides an environment variable not an argument.

Use this …

Code (gambas)

  1.  
  2. Exec ["gbr3", "GambasFolder/Executable/DocsViewer.gambas", "sTemp=XXX"]
  3.  
  4.  


you could use the "With" syntax in your program but should do this…

Code (gambas)

  1.  
  2. Public Sub Form_Open()
  3.  
  4.   If Env["sTemp"] then  ' Check for sTemp env variable
  5.     OpenFile(Env["sTemp"])
  6.  
  7.  

then this will work…
Exec ["gbr3", "GambasFolder/Executable/DocsViewer.gambas"] With ["sTemp=XXX"]

But it's not advised, it's better to use an argument than an env var
Online now: No Back to the top

Post

Posted
Rating:
#8
Guru
BruceSteers is in the usergroup ‘Guru’

bill-lancaster said


BTW I extract the argument value with Split(Args[1], "=")[1] is there a better way?


Yes, use the more advanced Args.class component
/comp/gb.args - Gambas Documentation
Online now: No Back to the top

Post

Posted
Rating:
#9
Guru
BruceSteers is in the usergroup ‘Guru’
Something like this shows how to use gb.args Args.class ..

the following example lets you use multiple filenames as args with or without the -f prefix.

Any arguments that are not handled by Args.Get, Args.Has, etc are considered files to open.

you can use the -f (–file) prefix but you do not need to.

Code (gambas)

  1.  
  2. Public sub Form_Open()
  3.  
  4.   Dim aFiles As New String[]
  5.  
  6.   Args.Begin("Title, shows as header when user type --help")  ' start processing args
  7.  
  8.   Dim sFile As String = Args.Get("f", "file" , "Open a File", "Path")  ' if user types -f "filename" then name is stored.
  9.  
  10.   aFiles = Args.End()  ' finish processing args, all unhandled args are returns as a list.
  11.  
  12.  If sFile Then aFiles.Add(sFile,0)  ' if -f or --file was used then put that file at head of the list.
  13.  
  14. If aFiles.Count Then  ' now open each filename given as an argument
  15.  For Each sFile In aFiles
  16.   OpenFileInNewTab(sFile)
  17.  
  18.  
  19.  
Online now: No Back to the top
1 guest and 0 members have just viewed this.