Gambas executable entry value

Post your Gambas programming questions here.
Post Reply
bill-lancaster
Posts: 195
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Gambas executable entry value

Post 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?
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Gambas executable entry value

Post 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"]
'
If at first you don't succeed , try doing something differently.
BruceS
bill-lancaster
Posts: 195
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Re: Gambas executable entry value

Post 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?
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Gambas executable entry value

Post 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"]

If at first you don't succeed , try doing something differently.
BruceS
User avatar
thatbruce
Posts: 168
Joined: Saturday 4th September 2021 11:29pm

Re: Gambas executable entry value

Post 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
Have you ever noticed that software is never advertised using the adjective "spreadable".
bill-lancaster
Posts: 195
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Re: Gambas executable entry value

Post 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
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Gambas executable entry value

Post 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
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Gambas executable entry value

Post 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
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Gambas executable entry value

Post 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

If at first you don't succeed , try doing something differently.
BruceS
Post Reply