How can I tell if running from stand-alone or compiler?

Mac OSX specific forum
WilliamL
Addict
Addict
Posts: 1255
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

How can I tell if running from stand-alone or compiler?

Post by WilliamL »

Easy one...

How can the program tell if it is running from the compiler or in stand-alone?

Is there a constant (with a value) or something else?
MacBook Pro-M1 (2021), Tahoe 26.1, PB 6.30b2
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post by akj »

I'm guessing as I don't have a MAC but I would have thought that in practice (though not always in theory) this code would do what you want:

Code: Select all

If LCase(GetPathPart(ProgramFilename()))= LCase(GetTemporaryDirectory())
  MessageRequester("Run Type", "Running from the IDE")
Else
  MessageRequester("Run Type", "Running as a stand-alone EXE")
EndIf
Anthony Jordan
case
Enthusiast
Enthusiast
Posts: 141
Joined: Thu Aug 07, 2003 11:09 am

Post by case »

there's no difference when running a pb executable from the ide or a compiled version , the compiler create an .exe then run it.

but you can set yourself a way to kow it

put something like

Code: Select all

global standalone.b=1 ; change it to 0 for a non standalone build
then use the variable for your program to know if it run from the compiler or not...
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

if the only way is a manual setting, you could also use a constant.
#STANDALONE = #False
would be better than a global variable...
oh... and have a nice day.
case
Enthusiast
Enthusiast
Posts: 141
Joined: Thu Aug 07, 2003 11:09 am

Post by case »

akj wrote:I'm guessing as I don't have a MAC but I would have thought that in practice (though not always in theory) this code would do what you want:

Code: Select all

If LCase(GetPathPart(ProgramFilename()))= LCase(GetTemporaryDirectory())
  MessageRequester("Run Type", "Running from the IDE")
Else
  MessageRequester("Run Type", "Running as a stand-alone EXE")
EndIf

that may not work if you compile the program in the same directory of the final build , like i do for some code that need files to be present.
WilliamL
Addict
Addict
Posts: 1255
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Post by WilliamL »

Thanks all.

I've been using the variable method as shown below.

Code: Select all

FilePath.s=GetCurrentDirectory()
If Len(AFilePath)<5
   ; gives / (one char) (this is stand-alone mode)
    FilePath=ProgramFilename() ; this works in stand-alone mode
    PBMode=0 ; in stand-alone
Else
  ;gives full file path
    PBMode=1 ; in compile mode
EndIf
MacBook Pro-M1 (2021), Tahoe 26.1, PB 6.30b2
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

this is only that long practicable, as long you don't compile the temporary exe into the source directory to access ressources in subdirectories more easily...
oh... and have a nice day.
freak
PureBasic Team
PureBasic Team
Posts: 5950
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

You can just go the Compiler Options -> Constants and enable the #PB_Editor_CreateExecutable constant. This way you know when the code is compiled from the editor.
quidquid Latine dictum sit altum videtur
WilliamL
Addict
Addict
Posts: 1255
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Post by WilliamL »

Thanks, freak, now we all know!
#PB_Editor_CreateExecutable
If enabled, this constants holds a value of 1 if the code is compiled with the "Create Executable" menu or 0 if "Compile/Run" was used.
Tried it and it works!
MacBook Pro-M1 (2021), Tahoe 26.1, PB 6.30b2
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: How can I tell if running from stand-alone or compiler?

Post by PB »

> How can the program tell if it is running from the compiler or in stand-alone?

For Windows (and probably cross-platform) I've been using this:

Code: Select all

CompilerIf #PB_Compiler_Debugger
  ; Do runtime code here.
CompilerElse
  ; Do final exe code here.
CompilerEndIf
No need to enable anything in every source. ;)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

@freak

always something new to discover...

thanx for that tip!


@PB

... afaik you can compile a standalone exe INCLUDING debugger support ...
oh... and have a nice day.
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post by akj »

@freak,

As most PB users would expect a constant that seems to relate to the compilation process to be mentioned in the 'Compiler Directives' section of the Help manual, I would like to request that a reference to (i.e. mention of) #PB_Editor_CreateExecutable be added to that help section. Pretty please.

Alternatively, can a facility be provided for [a copy of] the Help pages to be freely editable by registered PureBasic users? Of course, the edits would need to be vetted by 'The Management' but it would be a good way to quickly improve the quality and scope of the PB documentation which in my opinion is still quite minimalist.
Anthony Jordan
freak
PureBasic Team
PureBasic Team
Posts: 5950
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

akj wrote:@freak,

As most PB users would expect a constant that seems to relate to the compilation process to be mentioned in the 'Compiler Directives' section of the Help manual, I would like to request that a reference to (i.e. mention of) #PB_Editor_CreateExecutable be added to that help section. Pretty please.
Its not a feature of the compiler. Its a feature of the IDE, and it is documented in the IDE documentation. (if you use the commandline compiler, the constant will not be added).
akj wrote:Alternatively, can a facility be provided for [a copy of] the Help pages to be freely editable by registered PureBasic users? Of course, the edits would need to be vetted by 'The Management' but it would be a good way to quickly improve the quality and scope of the PB documentation which in my opinion is still quite minimalist.
There was a wiki once. It was taken down due to lack of user interest.
quidquid Latine dictum sit altum videtur
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> you can compile a standalone exe INCLUDING debugger support

How? The docs say it's never done that way, for speed reasons.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

PB wrote:> you can compile a standalone exe INCLUDING debugger support

How? The docs say it's never done that way, for speed reasons.
Use the demoversion :lol:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply