[SOLVED] Which OS system? lazarus / 21-General ---------------------------------------------------------------------- madref · 2023-10-10 08:29 Maybe a silly question but how can one determine which system is running (OSx/Windows/Linus)? ---------------------------------------------------------------------- Fibonacci · 2023-10-10 08:35 By looking at file system, checking if specific files and directories exists ---------------------------------------------------------------------- madref · 2023-10-10 08:36 There must be an easier way ---------------------------------------------------------------------- Fibonacci · 2023-10-10 08:37 This is the easiest I could think of Assuming you are some program and need to check that at run time ---------------------------------------------------------------------- AlexTP · 2023-10-10 08:41 you cannot get under which OS you are running, but can get for which OS app is compiled. example: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses InterfaceBase;   labelPlatform.Caption:= Format('%s-%s-%s, fpc %s', [    LowerCase({$I %FPCTARGETOS%}),    {$I %FPCTARGETCPU%},    GetLCLWidgetTypeName,    {$I %FPCVersion%}    ]); on Windows, you can get the OS version. https://wiki.freepascal.org/WindowsVersion ---------------------------------------------------------------------- MarkMLl · 2023-10-10 09:11 Quote from: madref on October 10, 2023, 10:29:37 amMaybe a silly question but how can one determine which system is running (OSx/Windows/Linus)? ... There must be an easier way It's LinuX and why must there be an easier way? As suggested, you can get a lot of info by looking at what the target of the compilation is. However that won't tell you if e.g. a binary is being run under an unexpected unix variant using an emulation shim. In the case of unix-like OSes, look to see if there's a file /etc/os- release , this comes from freedesktop.org and is widely supported. If it doesn't exist then you're on your own, but might be able to work things out from uname, the content of the /proc tree and so on (see e.g. https://apple.stackexchange.com/questions/255546/how-to-find- file-release-in-os-x-el-capitan-10-11-6). If you're running in a (Docker etc.) container then uname might tell you something about the guest, or might tell you something about the host. If you're running in a VM which sandboxes access to the host, then all bets are off. MarkMLl ---------------------------------------------------------------------- madref · 2023-10-10 09:13 I made it much easier for myself by looking at this article and now I am just using the compiler switches ---------------------------------------------------------------------- dseligo · 2023-10-10 11:07 Quote from: madref on October 10, 2023, 11:13:18 amI made it much easier for myself by looking at this article and now I am just using the compiler switches For a more comprehensive list of possible defines during compilation look here https://www.freepascal.org/docs-html/prog/progap7.html. ---------------------------------------------------------------------- Warfley · 2023-10-10 12:59 Just use ifdefs? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$if defined(windows)}platform:='Windows';{$elseif defined(Linux)}platform:='Linux';{$elseif defined(Darwin)}platform:='macOS';...{$endif} ---------------------------------------------------------------------- madref · 2023-10-11 22:10 I used Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   {$IFDEF WINDOWS} Code := 'Windows'; {$ENDIF}  {$IFDEF DARWIN} Code := 'macOS'; {$ENDIF}