* * *

Author Topic: Get Linux system information with Lazarus and FreePascal  (Read 530 times)

ClintonJMolina11

  • Newbie
  • Posts: 1
Get Linux system information with Lazarus and FreePascal
« on: November 07, 2018, 08:03:08 am »
I'm really new to Lazarus / FreePascal and I have not experienced Delphi before. I want to be able to get OS version information and user account types on both Windows and Linux. I find that there is a Windows system API, but can not find anything similar for Linux.

Is there a Linux System API for Lazarus / FreePascal and if so, how can I use it?

GetMem

  • Hero Member
  • *****
  • Posts: 3207
Re: Get Linux system information with Lazarus and FreePascal
« Reply #1 on: November 07, 2018, 08:19:12 am »
@ClintonJMolina11
Quote
Is there a Linux System API for Lazarus / FreePascal and if so, how can I use it?
AFAIK no, but you can use TProcess to run various Linux commands to get the info you need.
1. TProcess: http://wiki.freepascal.org/Executing_External_Programs#How_to_redirect_output_with_TProcess
2. Commands:  http://www.pixelbeat.org/cmdline.html

For example run "uname -a" to get kernel version and system architecture.

Thaddy

  • Hero Member
  • *****
  • Posts: 7140
Re: Get Linux system information with Lazarus and FreePascal
« Reply #2 on: November 07, 2018, 08:39:26 am »
@ClintonJMolina11
Quote
Is there a Linux System API for Lazarus / FreePascal and if so, how can I use it?
AFAIK no, but you can use TProcess to run various Linux commands to get the info you need.
Afaik yes. It is distributed over the BaseUnix, Unix and Linux and some xxxtypes units but the full system API is accessible in pure pascal.
You can even write most if not all utilities like e.g uname or top  in FPC if you have nothing else to do..
Most of the system API functions have an fp prefix (as compared to C equivalents) , but you can very easily translate any C code into Pascal.
E.g. Device queries go through fpioctl, everything that is a file can be opened by a simple THandlestream descendant and the full set of system calls is available.
But indeed you can also use Tprocess and call existing utilities.
« Last Edit: November 07, 2018, 08:55:21 am by Thaddy »
inline variables like in D10.3 are a bit like Brexit: if you are given the wrong information it sounds like a good idea. Every kid loves candy, but it makes you fat and your teeth will disappear.

dbannon

  • Sr. Member
  • ****
  • Posts: 328
Re: Get Linux system information with Lazarus and FreePascal
« Reply #3 on: November 07, 2018, 12:18:29 pm »
You can read the 'files' in /proc, its a window into the bowels of your machine. Try, for example reading (or just cat) /proc/cpuinfo.

The numbered directories in there refer to running processes, each has a lot of info to see if you poke around.....

Davo
Lazarus 1.8, Linux (and reluctantly Win10, OSX)

lucamar

  • Sr. Member
  • ****
  • Posts: 354
Re: Get Linux system information with Lazarus and FreePascal
« Reply #4 on: November 07, 2018, 12:23:53 pm »
Also, and one of the big advantages or Linux, you can consult the source of your favourite utilities (those you would call with TProcess) and learn what they do and how they do it. Then replicate it in Pascal :)
Been there, done that ... barely kept the timelines.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 1.8.4/fpc 3.0.4 - Ubuntu 10, Kubuntu 14, Windows XP SP3 (Home & Prof.) and various DOS incarnations.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus