Works in IDE; not when made as an executable

Post your Gambas programming questions here.
User avatar
grayghost4
Posts: 174
Joined: Wednesday 5th December 2018 5:00am
Location: Marengo, Illinois usa

Re: Works in IDE; not when made as an executable

Post by grayghost4 »

You forgot to:
Dim sText as string
Or you could just use Result100.

The variable name is not important (I think it is just Bruce's naming convention) starting a variable name with " i, s, f, sa, ...... " to indicate what the variable is.

https://en.wikipedia.org/wiki/Hungarian_notation

3.16.3 is the current version that most here are using.
mikejp56
Posts: 17
Joined: Tuesday 28th January 2020 1:19pm

Re: Works in IDE; not when made as an executable

Post by mikejp56 »

Hi grayghost4,
Thanks so much for your help. That nailed it!
But why do I need to use "Quote" instead of just using "TextArea.Text=Result100"?
I have used this on other parts of this project with no problems.
Thanks again.
Is there a list or a document that has ALL of the keywords and commands, maybe also with examples?
Regards,
mikejp56
User avatar
grayghost4
Posts: 174
Joined: Wednesday 5th December 2018 5:00am
Location: Marengo, Illinois usa

Re: Works in IDE; not when made as an executable

Post by grayghost4 »

Here are some sources of information about Gambas :

https://gambaswiki.org/wiki

https://wordpress.gambas.one/2019/08/17 ... -from-zip/

this is the best book that I have found for gambas :

https://www.barnesandnoble.com/w/beginn ... 0741494344

If you place the cursor on the word Quote and "control click" ( or any reserve word or command ) it will give you a description of the command under the cursor.

If you read through the "Did you know" thread above it will give you many tips and tricks for using the IDE and the language.
mikejp56
Posts: 17
Joined: Tuesday 28th January 2020 1:19pm

Re: Works in IDE; not when made as an executable

Post by mikejp56 »

Hi Guys,
So if I run the sub without the grep statement, it runs fine; it just gives the entire command output. When I run the sub with the grep statement, the text area or text box is empty.
Why would grep break this?
Regards,
mikejp56
mikejp56
Posts: 17
Joined: Tuesday 28th January 2020 1:19pm

Re: Works in IDE; not when made as an executable

Post by mikejp56 »

Hi Guys,
I have attached 3 screenshots from this problem.
From IDE.png
From IDE.png (88.59 KiB) Viewed 3728 times
From executable.png
From executable.png (76.44 KiB) Viewed 3728 times
Executable file.png
Executable file.png (50.88 KiB) Viewed 3728 times
1) From IDE is from the GAMBAS environment. Both text areas are filled in.
2) From executable is from the executable generated by the IDE. The textarea for the CPU is blank.
3) This is where GAMBAS has put the executable file.

So to my admittedly unprogrammer's mind, it appears that the executable is not happy with the grep command when used with the inxi -C command, but it is OK when used with the grep command when used with the bash command?
I am at a complete loss!
Regards,
mikejp56
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Works in IDE; not when made as an executable

Post by BruceSteers »

Just a note. Gambas uses sh by default in a Shell not bash.
Maybe that's the problem? (it may not be but sh does behave differently to bash)

To make gambas use bash you have to put the following code in....

Public Sub Form_Open()

  System.Shell = System.Find("bash")

  ' Now Shell will use bash not sh

End

and sorry to confuse.
i used Quote() so "I" could see what was being output, I did not mean you had to use it in your code (same for sText, it's just the name i used in my test)
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Works in IDE; not when made as an executable

Post by BruceSteers »

you are not using the "-c 0" flag i mentioned to remove the colour codes!

I find it does what you say if i do not omit the colours but it works if i do.
without using -c 0 my output running the exe is this...

"\x0312CPU: \x03\x0312Topology\x03 Quad Core \x0312model\x03 Intel Core i5-3470S \x0312bits\x03 64 \x0312type\x03 MCP \x0312L2 cache\x03 6144 KiB \x03\n \x0312Speed\x03 3350 MHz \x0312min/max\x03 1600/3600 MHz \x0312Core speeds (MHz)\x03 \x03121\x03 3353 \x03122\x03 3315 \x03123\x03 3557 \x03124\x03 3310 \x03\n"

So grep fails to find "model:"

for "inxi -C -c 0" output is this..
"CPU: Topology: Quad Core model: Intel Core i5-3470S bits: 64 type: MCP L2 cache: 6144 KiB \n Speed: 3429 MHz min/max: 1600/3600 MHz Core speeds (MHz): 1: 3253 2: 3586 3: 3453 \n 4: 3335 \n"

Try this..

Shell "inxi -C -c 0| grep -o -P '(?<=model: ).*(?=bits)'" To Result2

Last edited by BruceSteers on Wednesday 24th November 2021 1:52pm, edited 1 time in total.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Works in IDE; not when made as an executable

Post by BruceSteers »

I discovered this by using Quote() in the result to see any differences ;) :lol:
I could see the colour codes in the text.
The colour codes are interfering with your grep command

if you run a gambas app via a terminal or from the IDE it has a stdout terminal stream to use but if just running an app by clicking the icon it does not and commands can detect this and so output can differ.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Works in IDE; not when made as an executable

Post by BruceSteers »

PS.
You can yourself find if your running app has a parent terminal associated or not by using something like this..

If File.In.IsTerm Then
  ' app has a parent terminal so output formatting may occur
Else
  ' Terminal formatting may not occur
Endif
Just in case you need to know :)
If at first you don't succeed , try doing something differently.
BruceS
mikejp56
Posts: 17
Joined: Tuesday 28th January 2020 1:19pm

Re: Works in IDE; not when made as an executable

Post by mikejp56 »

Hi BruceSteers,
Thanks so much for your help...the -c 0 switch did the trick!
And thanks for explaining why it worked in the IDE but not as an executable.

Hi stevedee,
Also thanks for all of your help too!

I hope you both have a wonderful holiday season!

Regards,
mikejp56
Post Reply