Page 1 of 1
Gambas executable entry value
Posted: Friday 26th January 2024 9:51am
by bill-lancaster
I run a gambas executable from another gambas project by:-
Code: Select all
Exec ["/home/bill/GambasFolder/Executable/DocsViewer.gambas"]
How can I provide an entry value (a file name) to DocsViewer.gambas?
Re: Gambas executable entry value
Posted: Friday 26th January 2024 12:01pm
by BruceSteers
bill-lancaster wrote: ↑Friday 26th January 2024 9:51am
I run a gambas executable from another gambas project by:-
Code: Select all
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..
'
Exec ["gambas3", "/path/myproject"]
'
'or
Shell "gambas3 /path/myproject"
To provide environment variables use "With"
so terminal would be
env GB_GUI=gb.qt5 gambas3 /path/myproject
gambas Exec syntax....
'
Exec ["gambas3", "/path/myproject"] With ["GB_GUI=gb.qt5"]
'
Re: Gambas executable entry value
Posted: Saturday 27th January 2024 9:42am
by bill-lancaster
Thanks Bruce,
Having trouble with syntax,
Code: Select all
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?
Re: Gambas executable entry value
Posted: Saturday 27th January 2024 10:48am
by BruceSteers
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...
Exec ["/home/bill/GambasFolder/Executable/DocsViewer.gambas", "/path/to/thedoc/item.doc"]
Re: Gambas executable entry value
Posted: Saturday 27th January 2024 12:14pm
by thatbruce
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
Re: Gambas executable entry value
Posted: Saturday 27th January 2024 1:37pm
by bill-lancaster
Thanks again Bruce,
Code: Select all
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
Re: Gambas executable entry value
Posted: Saturday 27th January 2024 2:50pm
by BruceSteers
"With" provides an environment variable not an argument.
Use this ...
Exec ["gbr3", "GambasFolder/Executable/DocsViewer.gambas", "sTemp=XXX"]
you could use the "With" syntax in your program but should do this...
Public Sub Form_Open()
If Env["sTemp"] then ' Check for sTemp env variable
OpenFile(Env["sTemp"])
Endif
End
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
Re: Gambas executable entry value
Posted: Saturday 27th January 2024 3:01pm
by BruceSteers
bill-lancaster wrote: ↑Saturday 27th January 2024 1:37pm
BTW I extract the argument value with Split(Args[1], "=")[1] is there a better way?
Yes, use the more advanced Args.class component
https://gambaswiki.org/wiki/comp/gb.args
Re: Gambas executable entry value
Posted: Saturday 10th February 2024 3:05pm
by BruceSteers
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.
Public sub Form_Open()
Dim aFiles As New String[]
Args.Begin("Title, shows as header when user type --help") ' start processing args
Dim sFile As String = Args.Get("f", "file" , "Open a File", "Path") ' if user types -f "filename" then name is stored.
aFiles = Args.End() ' finish processing args, all unhandled args are returns as a list.
If sFile Then aFiles.Add(sFile,0) ' if -f or --file was used then put that file at head of the list.
If aFiles.Count Then ' now open each filename given as an argument
For Each sFile In aFiles
OpenFileInNewTab(sFile)
Next
Endif
End