[fpc-pascal] ExecuteProcess problem
Koenraad Lelong
fpascal1 at de-brouwerij.be
Tue Aug 25 14:31:21 CEST 2020
Hi,
I'm extending an old daemon so it writes the data to MQTT, using
mosquitto_pub.
To have a correct message (-m ...) I need to include double-quotes. But
it seems ExecuteProcess(exec,cmdline) splits the cmdline according some
rules if it's a single string.
When I tried to do it in a single string :
-h 127.0.0.1 -t solartopic -u user -P secret -i clientid -m "{\"Pac\":
458.00}"
I got :
Error: Unknown option 'Pac\":'.
So I need to make cmdline an array. How I do that ?
I tried :
MQTTStr : array [0..5] of ansistring;
...
MQTTStr[0]:='-h '+MQTTBroker;
MQTTStr[1]:='-t '+MQTTTopic;
MQTTStr[2]:='-u '+MQTTUser;
MQTTStr[3]:='-P '+MQTTPassw;
MQTTStr[4]:='-i '+MQTTClientID;
MQTTStr[5]:='-m "{\"'+ChanName+'\": '+TextValue+'}"';
ExecuteProcess(MQTTExec,MQTTStr));
But then :
Error: Unknown option '-h 127.0.0.1'.
Use 'mosquitto_pub --help' to see usage.
Thanks in advance
Koenraad
More information about the fpc-pascal
mailing list