Works in IDE; not when made as an executable

Post

Posted
Rating:
#1 (In Topic #765)
Trainee
 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
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
stevedee is in the usergroup ‘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:-

Code (gambas)

  1. Shell "inxi" To Result100

…and what I notice is that there are quite a few control characters in the output.
Image

(Click to enlarge)


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!
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
hi,  I found the flag -c 0 stops the colour output.

try this…

Shell "inxi -C -c 0 | grep -o -P '(?<=model:).*(?=bits)'"
Online now: No Back to the top

Post

Posted
Rating:
#4
Trainee
 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
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
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

Code (gambas)

  1. TextArea100.EnsureVisible
  2. TextArea100.Refresh
  3.  

And maybe set TextArea100.Wrap = True

All the best
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Regular
stevedee is in the usergroup ‘Regular’
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
Image

(Click to enlarge)


…so if you were hoping that your code would be universal, I think you will have problems, as the output varies between machines.
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Regular
stevedee is in the usergroup ‘Regular’

BruceSteers said

…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)
Online now: No Back to the top

Post

Posted
Rating:
#8
Trainee
 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
Online now: No Back to the top

Post

Posted
Rating:
#9
Guru
BruceSteers is in the usergroup ‘Guru’

stevedee said

BruceSteers said

…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.
Online now: No Back to the top

Post

Posted
Rating:
#10
Trainee
 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
Online now: No Back to the top

Post

Posted
Rating:
#11
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
You forgot to:

Code (gambas)

  1. 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.
Online now: Yes Back to the top

Post

Posted
Rating:
#12
Trainee
 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
Online now: No Back to the top

Post

Posted
Rating:
#13
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
Here are some sources of information about Gambas :

/ - 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.
Online now: Yes Back to the top

Post

Posted
Rating:
#14
Trainee
 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
Online now: No Back to the top

Post

Posted
Rating:
#15
Trainee
Hi Guys,
I have attached 3 screenshots from this problem.
Image

(Click to enlarge)

Image

(Click to enlarge)

Image

(Click to enlarge)

  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
Online now: No Back to the top

Post

Posted
Rating:
#16
Guru
BruceSteers is in the usergroup ‘Guru’
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….

Code (gambas)

  1.  
  2. Public Sub Form_Open()
  3.  
  4.   System.Shell = System.Find("bash")
  5.  
  6.   ' Now Shell will use bash not sh
  7.  
  8.  
  9.  
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)
Online now: No Back to the top

Post

Posted
Rating:
#17
Guru
BruceSteers is in the usergroup ‘Guru’
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..

Code (gambas)

  1.  
  2. Shell "inxi -C -c 0| grep -o -P '(?<=model: ).*(?=bits)'" To Result2
  3.  
  4.  
Online now: No Back to the top

Post

Posted
Rating:
#18
Guru
BruceSteers is in the usergroup ‘Guru’
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.
Online now: No Back to the top

Post

Posted
Rating:
#19
Guru
BruceSteers is in the usergroup ‘Guru’
PS.
You can yourself find if your running app has a parent terminal associated or not by using something like this..

Code (gambas)

  1.  
  2. If File.In.IsTerm Then
  3.   ' app has a parent terminal so output formatting may occur
  4.   ' Terminal formatting may not occur
  5.  

Just in case you need to know :)
Online now: No Back to the top

Post

Posted
Rating:
#20
Trainee
 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
Online now: No Back to the top
1 guest and 0 members have just viewed this.