Works in IDE; not when made as an executable

Post your Gambas programming questions here.
mikejp56
Posts: 13
Joined: Tuesday 28th January 2020 1:19pm

Works in IDE; not when made as an executable

Post by mikejp56 » Monday 22nd November 2021 1:26am

I am writing an application as an exercise that displays different information about my PC, such as Linux version, available hardware, installed repositories, etc. I have 3 separate screens for 3 different types of data. The data is obtained by using "Shell" and then terminal commands. The results are dimensioned as strings and displayed in a text area.
Right now the 3 screens that I have are called Network, Hardware, and Software. All 3 work in the IDE, but when I make an executable, called forms.gambas, the Network and Software screens work fine, but the Hardware screen is barely filled, and the data that is filled has non alphanumeric characters mixed in with the data.
As an experiment I have a form with a text area and a push button. The push button runs the same shell command as one of the hardware entries; the one for displaying the installed CPU. This code is :

Public Sub Button4_Click()
Dim Result100 As String
Shell "inxi -C | grep -o -P '(?<=model:).*(?=bits)'" To Result100
TextArea100.Text = Result100
End

When the button4 is pressed in the IDE the textarea100.text displays the processor installed in my PC. But when I make an executable, called forms.gambas, and then click on the icon, the form opens up. But when I press Button4, the testarea stays empty.
I am not a programmer, just a hardware engineer playing with some interesting software.
Any help would be greatly appreciated!
Regards,
mikejp56

User avatar
stevedee
Posts: 468
Joined: Monday 20th March 2017 6:06pm

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

Post by stevedee » Monday 22nd November 2021 7:54am

mikejp56 wrote:
Monday 22nd November 2021 1:26am
...When the button4 is pressed in the IDE the textarea100.text displays the processor installed in my PC. But when I make an executable, called forms.gambas, and then click on the icon, the form opens up. But when I press Button4, the testarea stays empty...
I can't reproduce your problem because the output from inxi does not include the word "model" on my computer. So I modified your code:-
Shell "inxi" To Result100
...and what I notice is that there are quite a few control characters in the output.
inxiOutput.png
inxiOutput.png (20.54 KiB) Viewed 158 times
My suggestion is that you take a close look at the contents of the string Results100 (e.g. put a breakpoint in your code) or, better still, do the filtering in Gambas after collecting the full output from inxi.

I hope that helps.



p.s.
Man, you are not "...just a hardware engineer...". You are a hardware engineer.
Us Hard boys have got to stick together!

User avatar
BruceSteers
Posts: 677
Joined: Thursday 23rd July 2020 5:20pm

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

Post by BruceSteers » Monday 22nd November 2021 9:58am

hi, I found the flag -c 0 stops the colour output.

try this...

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

If at first you don't succeed , try it differently.

mikejp56
Posts: 13
Joined: Tuesday 28th January 2020 1:19pm

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

Post by mikejp56 » Monday 22nd November 2021 2:33pm

Hi stevedee,
This is what I get when I run inxi -C:

$ inxi -C
CPU:
Info: Dual Core model: AMD A4-3300M APU with Radeon HD Graphics bits: 64
type: MCP cache: L2: 2 MiB
Speed: 799 MHz min/max: 800/1900 MHz Core speeds (MHz): 1: 799 2: 804
This properly displays AMD A4-3300M APU with Radeon HD Graphics in terminal and when I run the program in the IDE.
When I make an executable and run it, I get a blank text area; there is nothing in it.
I hope that is a better explanation of what I am seeing.
Thanks for your quick response.

Hi BruceSteers,
Thanks for that tidbit! That will definitely go into my notebook!

Regards,
mikejp56

User avatar
BruceSteers
Posts: 677
Joined: Thursday 23rd July 2020 5:20pm

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

Post by BruceSteers » Monday 22nd November 2021 3:11pm

Here's the differences i see between exe and IDE..

IDE:
"CPU:\n Topology: Quad Core model: Intel Core i5-3470S bits: 64 \n type: MCP L2 cache: 6144 KiB \n Speed: 3260 MHz min/max: 1600/3600 MHz \n Core speeds (MHz): 1: 3306 2: 3307 3: 3245 4: 3460 \n"

Exe:
"CPU: Topology: Quad Core model: Intel Core i5-3470S bits: 64 type: MCP L2 cache: 6144 KiB \n Speed: 3314 MHz min/max: 1600/3600 MHz Core speeds (MHz): 1: 3297 2: 3322 3: 3464 \n 4: 3279 \n"

It just seems to add \n line feeds in different places.
be sure to use the following to see the text
TextArea100.EnsureVisible
TextArea100.Refresh
And maybe set TextArea100.Wrap = True

All the best
Wishing well
Bruce

If at first you don't succeed , try it differently.

User avatar
stevedee
Posts: 468
Joined: Monday 20th March 2017 6:06pm

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

Post by stevedee » Monday 22nd November 2021 3:16pm

Yes, I'm sorry Mike, I did not directly answer your question.
I don't know why you get different results in IDE to the EXE. I was just suggesting that you need to investigate the control characters as they may be giving unreliable results.

This is what happens when I run inxi -C
inixProblem.png
inixProblem.png (34 KiB) Viewed 136 times
...so if you were hoping that your code would be universal, I think you will have problems, as the output varies between machines.

User avatar
stevedee
Posts: 468
Joined: Monday 20th March 2017 6:06pm

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

Post by stevedee » Monday 22nd November 2021 3:21pm

BruceSteers wrote:
Monday 22nd November 2021 3:11pm
...It just seems to add \n line feeds in different places...
That's weird, I get escape characters were you get line feeds (i.e. x1B or 27 decimal)

mikejp56
Posts: 13
Joined: Tuesday 28th January 2020 1:19pm

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

Post by mikejp56 » Monday 22nd November 2021 6:14pm

Hi stevedee and BruceSteers,
One other thing that I forgot to mention, in the Warnings pane at the bottom I get the following: Class name hidden by global declaration. Then it refers to Class form4 and line 9. Here is the first bunch of lines of form4.class:

' Gambas class file




Public Sub Button42_Click()

FMain.Show
Form2.Close
Form3.Close
Form4.Close

End

Public Sub Form_Open()
'OS Version
Dim result41 As String
'Shell "cat systemreport.txt | grep -o -P '(?<=Distro:).*(?= )'" To result41
Shell "lsb_release -d -s" To result41
'Shell "inxi -S | grep -o -P '(?<=Distro:).*(?= )'" To result41
TextArea41.Text = result41
'TextBox41.Text = result41

Any idea what that refers to?
Thanks again guys!
Regards,
mikejp56

User avatar
BruceSteers
Posts: 677
Joined: Thursday 23rd July 2020 5:20pm

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

Post by BruceSteers » Tuesday 23rd November 2021 3:56am

stevedee wrote:
Monday 22nd November 2021 3:21pm
BruceSteers wrote:
Monday 22nd November 2021 3:11pm
...It just seems to add \n line feeds in different places...
That's weird, I get escape characters were you get line feeds (i.e. x1B or 27 decimal)
yeah i used

Shell "inxi -C -c 0" To sText
TextArea1.Text =Quote(sText)

That omitted the color codes and showed the LFs as \n for me.
Wishing well
Bruce

If at first you don't succeed , try it differently.

mikejp56
Posts: 13
Joined: Tuesday 28th January 2020 1:19pm

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

Post by mikejp56 » Tuesday 23rd November 2021 1:02pm

Hi BruceSteers,
I tried your change using sText, so my code now looks like this:

Public Sub Button4_Click()
Dim Result100 As String
Shell "inxi -C -c 0" To sText
TextArea100.Text = Quote(sText)
End

WhenI run it I get "Unknown identifier: sText.

Perhaps we have different versions of Gambas3? My version is 3.16.3.
Thanks again for your help, and have a great thanksgiving.
Regards,
mikejp56

Post Reply