Forum > Linux

Read a config file

(1/2) > >>

This seems to be a stupid question but I'm from the Windows world and not that firm with Linux....

Here is my task: I'll need to create a small daemon that polls data from a webserver.
I managed to run it as a windows service but the code shall work on a Raspberry Pi so FPC is the obvious choice ;)

Now... I'm familiar in using ini files and TRegistry in Windows but what is that equivalent to read .conf files in Linux? My search wasn't that fruitful so I wanted to ask here...

Thanks in advance.

There is really no difference. If you use an ini file under windows, you can also do that under linux.
A .conf file is just like an ini file plain text, so basically the same. It is how you want to USE the ini or conf file that matters.
And that is up to your programming skills. (you can also use a conf file on Windows if you decide to do so!)

As Thaddy said, you can use an INI file under Linux. But there is a nice example of reading a Linux-style (?) configuration file here.

For the registry, I don't know.

Link is dubious and not working. DO NOT USE.
It works again. But that Rosetta code entry is shamefully badly written.
I will change that when I get home. Or almost everybody else can beat me to it. It is THAT bad....
Look at the delphi entry for much better code.
But it needs a review for both entries.

Hello mikerabat,

attached are two examples of how to save the window values so that they are preserved on restart.

The variant in the XReg folder uses TRegistry.
TRegistry is implemented in Lazarus so that it is cross-platform. ( )
I built a small unit for it, which can write string, integer, boolean, etc. into the registry and read from it.
The whole thing works also under Linux, there registry accesses are stored automatically in the folder .config in a corresponding XML.

Advantage: the program settings are BS-specific in the "right" place and are always accessible.

The variant in the folder XIni uses TIniFile.
With this variant one can write a Ini file into any folder.

Advantage: you can save the program settings where you want.

Greetings Roland


[0] Message Index

[#] Next page

Go to full version