Works in IDE; not when made as an executable
Posted
#1
(In Topic #765)
Trainee
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
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
Posted
Regular

mikejp56 said
…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:-
…and what I notice is that there are quite a few control characters in the output.
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!
Posted
Guru

try this…
Shell "inxi -C -c 0 | grep -o -P '(?<=model
Posted
Trainee
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
Posted
Guru

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
Code (gambas)
- TextArea100.EnsureVisible
- TextArea100.Refresh
And maybe set TextArea100.Wrap = True
All the best
Posted
Regular

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
…so if you were hoping that your code would be universal, I think you will have problems, as the output varies between machines.
Posted
Regular

That's weird, I get escape characters were you get line feeds (i.e. x1B or 27 decimal)BruceSteers said
…It just seems to add \n line feeds in different places…
Posted
Trainee
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
Shell "lsb_release -d -s" To result41
'Shell "inxi -S | grep -o -P '(?<=Distro
TextArea41.Text = result41
'TextBox41.Text = result41
Any idea what that refers to?
Thanks again guys!
Regards,
mikejp56
Posted
Guru

stevedee said
That's weird, I get escape characters were you get line feeds (i.e. x1B or 27 decimal)BruceSteers said
…It just seems to add \n line feeds in different places…
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.
Posted
Trainee
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
Posted
Enthusiast

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.
Posted
Trainee
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
Posted
Enthusiast

/ - Gambas Documentation
https://wordpress.gambas.one/2019/08/17/programming-gambas-from-zip/
this is the best book that I have found for gambas :
https://www.barnesandnoble.com/w/beginners-guide-to-gambas-revised-edition-john-rittinghouse/1112306018?ean=9780741494344
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.
Posted
Trainee
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
Posted
Trainee
I have attached 3 screenshots from this problem.
- From IDE is from the GAMBAS environment. Both text areas are filled in.
- From executable is from the executable generated by the IDE. The textarea for the CPU is blank.
- 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
Posted
Guru

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….
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)
Posted
Guru

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..
Posted
Guru

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.
Posted
Guru

Posted
Trainee
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
1 guest and 0 members have just viewed this.







