How to send operating system commands (Linux on RPi)?
I need to include the ability to switch on and off the WiFi network
connection of a Raspberry Pi3 running Raspbian Jessie into my
The commands I am looking at now are:
sudo ifup wlan0
sudo ifdown wlan0
How could this be accomplished in a FreePascal program running as user
The Pi will be multihomed (there is an Ethernet network connection in
addition to the WiFi) and it has been preconfigured to connect to a
specific SSID in the conf file for WiFi.
I want my program to be able to switch on the device hosting the WiFi
Access Point using relays (already done), then command the RPi to
connect to the now active Access Point immediately.
Time is of importance here and with just switching on the WiFi device
I get connection delays varying from 20 seconds to several minutes.
So it seems like a specific command to tell the operating system to
connect to WiFi is needed....
Re: How to send operating system commands (Linux on RPi)?
Am 02.07.2016 07:55 schrieb "Bo Berglund" <[hidden email]>:
> On Sat, 02 Jul 2016 01:12:34 +0200, Bo Berglund
> <[hidden email]> wrote:
> >The commands I am looking at now are:
> >sudo ifup wlan0
> >sudo ifdown wlan0
> >How could this be accomplished in a FreePascal program running as user
> To be specific I would like to know how I can send any command to the
> Linux operating system from my FreePascal program?
> Just doing this seems not to cut it:
> writeln('sudo ifup wlan0');
> This just *displays* the text on the program console, but I want it to
> go to the operating system as a command...
> On Windows one has to start cmd with the wanted command as a
> parameter, what is the corresponding method on Linux from within
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.
>Am 02.07.2016 07:55 schrieb "Bo Berglund" <[hidden email]>:
>> On Windows one has to start cmd with the wanted command as a
>> parameter, what is the corresponding method on Linux from within
>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
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:
-> 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