[fpc-pascal] How to send operating system commands (Linux on RPi)?

Bo Berglund bo.berglund at gmail.com
Sat Jul 2 10:05:28 CEST 2016

On Sat, 2 Jul 2016 09:21:17 +0200, Sven Barth
<pascaldragon at googlemail.com> wrote:

>Am 02.07.2016 07:55 schrieb "Bo Berglund" <bo.berglund at gmail.com>:
>> On Windows one has to start cmd with the wanted command as a
>> parameter, what is the corresponding method on Linux from within
>> FreePascal?
>Either fpsystem() from unit BaseUnix (this is the FPC variant of the C
>system() call) or TProcess if you should need to provide password input on
>a GUI.

this seems to work:

if arg = '1' then
   cmd := 'ifup wlan0'
else if arg = '0' then
   cmd := 'ifdown wlan0';

S := fpsystem('/usr/bin/sudo ' + cmd);

Now I just have to deal with the error when executing an ifdown
command when the wlan0 is already down. Strange that a command should
result in an error message if the result of the command is already
present at the start...

Reminds me of some similar errors on a CNC machine controller I
automated 15 years ago:
delete filename
-> ERROR: filename does not exist!

Such messages should not exist either, if one wants to delete a file
and it is not existing then the mission is accomplished from the start
and there should not be an error message...

In this case the Raspbian system generates:

sudo ifdown wlan0
ifdown: interface wlan0 not configured


sudo ifup wlan0
ifup: interface wlan0 already configured

Well, luckily I saw it so I can handle these "errors"

Bo Berglund
Developer in Sweden

More information about the fpc-pascal mailing list