Discussion:
who to detect if are running inside IDE
(too old to reply)
PICCORO McKAY Lenz
2017-07-03 17:23:44 UTC
Permalink
a piece of code to who to detect if are running inside IDE? any ideas how
to?

Lenz McKAY Gerardo (PICCORO)
http://qgqlochekone.blogspot.com
ML
2017-07-03 17:33:02 UTC
Permalink
Post by PICCORO McKAY Lenz
a piece of code to who to detect if are running inside IDE? any ideas how
to?
Lenz McKAY Gerardo (PICCORO)
http://qgqlochekone.blogspot.com
In the old days of VB6 I tried to print the result of 1/0 to the DEBUG
pane. Since output to the debug pane is ignored in VB6 compiled, there
would be no error in the final compiled app.
I don't know if Gambas does the same, but try this:

Function InIDE() As Boolean

Dim retVal As Boolean = False

Try Debug (1/0)
retVal = (Error.Code <> 0)
Error.Clear

Return retVal

End

Hope it helps,
zxMarce
Jussi Lahtinen
2017-07-03 18:16:47 UTC
Permalink
I don't know how this reacts to Gambas scripts, but for "normal" projects
it works.

#If Exec
Print "Executable"
#Else
Print "IDE"
#Endif



Jussi
Post by PICCORO McKAY Lenz
a piece of code to who to detect if are running inside IDE? any ideas how
to?
Lenz McKAY Gerardo (PICCORO)
http://qgqlochekone.blogspot.com
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
https://lists.sourceforge.net/lists/listinfo/gambas-user
Tobias Boege
2017-07-03 18:40:46 UTC
Permalink
Post by PICCORO McKAY Lenz
a piece of code to who to detect if are running inside IDE? any ideas how
to?
Exact same question here: https://sourceforge.net/p/gambas/mailman/message/34204796/

If I may add something to the things said in the above thread: you could try
to get the parent PID of your Gambas process and determine if it's the IDE.

If you always run on Linux you can probably use the /proc filesystem to get
the path to the executable of your parent process or its command line. Then
it depends on if you want to trust that the user always installs the IDE as
"gambas3.gambas", for instance. Examining the parent process will probably
not work anymore if you run your process *from the IDE* but through gb.httpd
or through xterm (which are options in the IDE).

I'm convinced that no matter how you try to detect if you're run by the IDE
or not, someone can create an environment where your test gives the wrong
answer. I still stand by my statement from two years ago: you shouldn't care
where your program is run from in the first place. What problem are you
trying to solve by knowing that?

Regards,
Tobi
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
Karl Reinl
2017-07-03 19:51:42 UTC
Permalink
Post by Tobias Boege
Post by PICCORO McKAY Lenz
a piece of code to who to detect if are running inside IDE? any ideas how
to?
Exact same question here: https://sourceforge.net/p/gambas/mailman/message/34204796/
If I may add something to the things said in the above thread: you could try
to get the parent PID of your Gambas process and determine if it's the IDE.
If you always run on Linux you can probably use the /proc filesystem to get
the path to the executable of your parent process or its command line. Then
it depends on if you want to trust that the user always installs the IDE as
"gambas3.gambas", for instance. Examining the parent process will probably
not work anymore if you run your process *from the IDE* but through gb.httpd
or through xterm (which are options in the IDE).
I'm convinced that no matter how you try to detect if you're run by the IDE
or not, someone can create an environment where your test gives the wrong
answer. I still stand by my statement from two years ago: you shouldn't care
where your program is run from in the first place. What problem are you
trying to solve by knowing that?
Regards,
Tobi
Salut Tobi,

I use (since gambas1) the project Arguments from the IDE. I set a ISIDE.

Sub chkIfIsIDE()
Dim nI As Integer
bIsIDE = False
For nI = 0 To Application.Args.Count - 1
' PRINT Application.Args[nI]
If InStr(UCase(Application.Args[nI]), "ISIDE") > 0 Then
bIsIDE = True
Endif
Next
End

So if I don't call my project with a parameter called ISIDE, I can be
sure .I ran in the IDE.

And the use is, I set the first key of my DB to 9999 that is my
Test-Mandant that's just a copy from one of my Mandants in my DB.
So no problems with crashing DB-data, that's the problem I solved with!.
--
Amicalement
Charlie
Karl Reinl
2017-07-03 20:00:26 UTC
Permalink
Post by Tobias Boege
Post by PICCORO McKAY Lenz
a piece of code to who to detect if are running inside IDE? any ideas how
to?
Exact same question here: https://sourceforge.net/p/gambas/mailman/message/34204796/
If I may add something to the things said in the above thread: you could try
to get the parent PID of your Gambas process and determine if it's the IDE.
If you always run on Linux you can probably use the /proc filesystem to get
the path to the executable of your parent process or its command line. Then
it depends on if you want to trust that the user always installs the IDE as
"gambas3.gambas", for instance. Examining the parent process will probably
not work anymore if you run your process *from the IDE* but through gb.httpd
or through xterm (which are options in the IDE).
I'm convinced that no matter how you try to detect if you're run by the IDE
or not, someone can create an environment where your test gives the wrong
answer. I still stand by my statement from two years ago: you shouldn't care
where your program is run from in the first place. What problem are you
trying to solve by knowing that?
Regards,
Tobi
Salut Tobi,

I use (since gambas1) the project Arguments from the IDE. I set a ISIDE.

Sub chkIfIsIDE()
Dim nI As Integer
bIsIDE = False
For nI = 0 To Application.Args.Count - 1
' PRINT Application.Args[nI]
If InStr(UCase(Application.Args[nI]), "ISIDE") > 0 Then
bIsIDE = True
Endif
Next
End

So if I don't call my project with a parameter called ISIDE, I can be
sure .I ran in the IDE.

And the use is, I set the first key of my DB to 9999 that is my
Test-Mandant that's just a copy from one of my Mandants in my DB.
So no problems with crashing DB-data, that's the problem I solved with!.

Sorry : Mandant = mandator
Tobias Boege
2017-07-03 20:36:14 UTC
Permalink
Post by Karl Reinl
Post by Tobias Boege
Post by PICCORO McKAY Lenz
a piece of code to who to detect if are running inside IDE? any ideas how
to?
Exact same question here: https://sourceforge.net/p/gambas/mailman/message/34204796/
If I may add something to the things said in the above thread: you could try
to get the parent PID of your Gambas process and determine if it's the IDE.
If you always run on Linux you can probably use the /proc filesystem to get
the path to the executable of your parent process or its command line. Then
it depends on if you want to trust that the user always installs the IDE as
"gambas3.gambas", for instance. Examining the parent process will probably
not work anymore if you run your process *from the IDE* but through gb.httpd
or through xterm (which are options in the IDE).
I'm convinced that no matter how you try to detect if you're run by the IDE
or not, someone can create an environment where your test gives the wrong
answer. I still stand by my statement from two years ago: you shouldn't care
where your program is run from in the first place. What problem are you
trying to solve by knowing that?
Regards,
Tobi
Salut Tobi,
I use (since gambas1) the project Arguments from the IDE. I set a ISIDE.
Sub chkIfIsIDE()
Dim nI As Integer
bIsIDE = False
For nI = 0 To Application.Args.Count - 1
' PRINT Application.Args[nI]
If InStr(UCase(Application.Args[nI]), "ISIDE") > 0 Then
bIsIDE = True
Endif
Next
End
So if I don't call my project with a parameter called ISIDE, I can be
sure .I ran in the IDE.
And the use is, I set the first key of my DB to 9999 that is my
Test-Mandant that's just a copy from one of my Mandants in my DB.
So no problems with crashing DB-data, that's the problem I solved with!.
Sorry : Mandant = mandator
Yes, and, in my opinion, you solved it the right way, by introducing
a proper interface which the user has to know and respect. Your program
doesn't guess, it is instructed.

Regards,
Tobi
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
a***@gmail.com
2017-07-03 20:38:24 UTC
Permalink
On Mon, 3 Jul 2017 20:40:46 +0200
Post by Tobias Boege
I'm convinced that no matter how you try to detect if you're run by the IDE
or not, someone can create an environment where your test gives the wrong
answer. I still stand by my statement from two years ago: you shouldn't care
where your program is run from in the first place. What problem are you
trying to solve by knowing that?
Regards,
Tobi
Since you asked :-)

Laziness!

Many times I have a menu item in a form that just "Stop"s the program i.e.

Private Sub mnuDebug()
Stop
End

then in the Form_Open()

#If Exec
mnuDebug.Visible = False
#Endif

So at development time, or when the customer has a problem, I almost always have a way to stop the program when it's running in the IDE.

All this does is "tidy up" the program automatically when run outside the IDE. If a user wants to go to the extent of creating a non-x version of the program just to see that menu item - which will do nothing anyway since the Stop is ignored - then all I can say is "Good luck to them."

There are probably trickier or even "more correct" ways to hide a menu item at runtime, but hey! Three lines and "As Far As I Care" - problem solved.

b
--
B Bruen <***@gnail.com (sort of)>
Jussi Lahtinen
2017-07-03 22:42:07 UTC
Permalink
I don't understand why you need stop menu to your project. Why can't you
just use the stop button from the IDE?


Jussi
Post by a***@gmail.com
On Mon, 3 Jul 2017 20:40:46 +0200
Post by Tobias Boege
I'm convinced that no matter how you try to detect if you're run by the
IDE
Post by Tobias Boege
or not, someone can create an environment where your test gives the wrong
answer. I still stand by my statement from two years ago: you shouldn't
care
Post by Tobias Boege
where your program is run from in the first place. What problem are you
trying to solve by knowing that?
Regards,
Tobi
Since you asked :-)
Laziness!
Many times I have a menu item in a form that just "Stop"s the program i.e.
Private Sub mnuDebug()
Stop
End
then in the Form_Open()
#If Exec
mnuDebug.Visible = False
#Endif
So at development time, or when the customer has a problem, I almost
always have a way to stop the program when it's running in the IDE.
All this does is "tidy up" the program automatically when run outside the
IDE. If a user wants to go to the extent of creating a non-x version of the
program just to see that menu item - which will do nothing anyway since the
Stop is ignored - then all I can say is "Good luck to them."
There are probably trickier or even "more correct" ways to hide a menu
item at runtime, but hey! Three lines and "As Far As I Care" - problem
solved.
b
--
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
https://lists.sourceforge.net/lists/listinfo/gambas-user
bb
2017-07-03 22:46:44 UTC
Permalink
Post by Jussi Lahtinen
I don't understand why you need stop menu to your project. Why can't you
just use the stop button from the IDE?
Jussi
Coz it stops at a defined place, not just next time the eventloop runs.

b
Jussi Lahtinen
2017-07-03 22:51:28 UTC
Permalink
Post by bb
Coz it stops at a defined place, not just next time the eventloop runs.
The eventloop needs to hit menu click for that to happen anyway... also I
don't get why that matters. But I guess it's up to your taste.



Jussi
PICCORO McKAY Lenz
2017-07-03 23:08:27 UTC
Permalink
Post by Jussi Lahtinen
Post by bb
Coz it stops at a defined place, not just next time the eventloop runs.
i matters, due depends on their environment and focused target objectives..
seems gambas developers have lack of vision...

some users mails and trick sound pretty rare.. but area prooff of variety
of needs.. that comes from externa vendor domination.. like me.. that many
things dont exits in gambas.. but i building..
Post by Jussi Lahtinen
The eventloop needs to hit menu click for that to happen anyway... also I
don't get why that matters. But I guess it's up to your taste.
Jussi
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
https://lists.sourceforge.net/lists/listinfo/gambas-user
PICCORO McKAY Lenz
2017-07-03 22:44:31 UTC
Permalink
Post by Tobias Boege
Exact same question here: https://sourceforge.net/p/
gambas/mailman/message/34204796/
its does work for scripts, gambas.cgi or normal excecutables?
Post by Tobias Boege
answer. I still stand by my statement from two years ago: you shouldn't care
where your program is run from in the first place. What problem are you
trying to solve by knowing that?
when run from ide i can take care of a local db , set local paths..

if run from NOT-ide so then must detect system behaviour and user right
paths..

currenlty some things are not distro agnostic and/or are user specific or
user-wide only... like the examples.. /gambas farm installation of
programs..
Post by Tobias Boege
Regards,
Tobi
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
https://lists.sourceforge.net/lists/listinfo/gambas-user
PICCORO McKAY Lenz
2017-07-04 16:59:40 UTC
Permalink
so in short investigations i have

Public Sub Main()
print "running"
#If Exec
print "in ide"
#Endif
End

so testing by normal steps to compile produce a exec (either a cgi or not)
so works for cgi:

$ gbc3 -ga
$ gba3
$ ./test.gambas
running

but for other cases i see tha if gambas archiver for executables are not
run for distribute, it fails:

$ gbx3 /tmp/testexec
running

in the reference mail it fails, but for production detection are good..
due its only for set paths, vars and environment

this due, another way its detecting the gambas runtime environment.. seem
gambas create a lof of files in /proc, based on Application.Id.. and also
in "/tmp" ...

i'm very curious about how gambas made this in cygwin installations, and or
in macos/freebsd flavors (if any)
Post by PICCORO McKAY Lenz
Post by Tobias Boege
Exact same question here: https://sourceforge.net/p/gamb
as/mailman/message/34204796/
its does work for scripts, gambas.cgi or normal excecutables?
Continue reading on narkive:
Loading...