Alex Rivera | Logout

Get Linux system info with Lazarus and FreePascal

Asked 2011-11-12T16:35:24.553
8

I am really new to Lazarus/FreePascal and I have no prior Delphi experience. I want to be able to get OS version information and user account type on both WIndows and Linux. I saw that there is a Windows system API, but could not find anything similar for Linux.

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

Edit
Report

1 Answer

2
  1. There is a "Unix" unit, you can check if what you want is in there.

I want to be able to get OS version information

What does this mean exactly? You can use the output of "uname -a" (Called from TProcess), depending on your needs. There are also files like /etc/redhat-release, etc., but they may vary by distribution.

and user account type on both Windows and Linux.

Probably what you want in Unix is to see what groups the user is in. (There are various ways to do this).

I saw that there is a Windows system API, but could not find anything similar for Linux.

Linux tends to follow the "Everything is a file" approach, so somewhere there is usually a file (or pseudo-file) you can read with the information you want. In general, Unix is more flexible than Windows. For example, in Windows there is probably an API call to get the number of processors or speed in Mhz. In Linux, you can look in /dev/cpuinfo and parse that info as a text file.

There are various flavors of Unix, and even within Linux, various distributions. You can of course narrow the scope of what you want to do by supporting only certain distributions for the time being.

answered 2012-02-03T08:01:03.893

Your Answer