Converting QString to a quoted shell argument.
-
Hello all
For the RefPerSys inference engine project (GPLv3+, for Linux only) on https://github.com/RefPerSys/RefPerSys/ we are developing a Qt6 graphical interface (GPLv3+) on https://github.com/bstarynk/misc-basile/blob/master/q6refpersys.cc
The q6refpersys program (a Qt6 interface) will communicate with the RefPerSys inference engine thru fifos or sockets (probably using some JSONRPC protocol)
We need to convert a QString to some shell-quoted thing. GTK provides the https://docs.gtk.org/glib/func.shell_quote.html and we need the Qt6 equivalent of it. This is useful for displaying literal strings and for debugging messages.
Also usefu to convert QString into JSON textual representation of it
Thanks for reading.
Regards from near Paris in France
Basile Starynkevitch -
I'm not aware of such a function in Qt. And I don't see why you would need it. QProcess is doing the correct things with the arguments passed.
-
@Basile_Starynkevitch
I don't know what your command is or how you are presently sending it toQProcess
as you do not show these.You can normally leave the correct quoting to
QProcess
with an argument list. If, for some reason, you have a string and want to split it into arguments forQProcess
you can use QStringList QProcess::splitCommand(QStringView command). Also void QProcess::startCommand(const QString &command, QIODeviceBase::OpenMode mode = ReadWrite) presumably uses that internally.Note however that you reference https://docs.gtk.org/glib/func.shell_quote.html and that says
Quotes a string so that the shell (/bin/sh) will interpret the quoted string to mean unquoted_string.
Quoting to a shell like
/bin/sh
can have its own rules. For example,echo '$HOME'
andecho "$HOME"
behave differently. I don't know how/whether you deal with that. And your GLib shell_quote ignores this.