On Wed, 18 Sep 2019 17:23:17 +0300 "Yordan Karadzhov (VMware)" <y.karadz@xxxxxxxxx> wrote: > +/** > + * Separate the command line arguments inside the string taking into account > + * possible shell quoting and new lines. > + */ > +QStringList splitArguments(QString cmd) > +{ > + QString::SplitBehavior opt = QString::SkipEmptyParts; > + int i, progress = 0, size; > + QStringList argv; > + QChar quote = 0; > + > + /* Remove all new lines. */ > + cmd.replace("\\\n", " "); > + > + size = cmd.count(); > + auto lamMid = [&] () {return cmd.mid(progress, i - progress);}; > + for (i = 0; i < size; ++i) { > + if (cmd[i] == '\\') { > + cmd.remove(i, 1); > + size --; > + continue; > + } > + > + if (cmd[i] == '\'' || cmd[i] == '"') { > + if (quote.isNull()) { > + argv << lamMid().split(" ", opt); > + quote = cmd[i++]; > + progress = i; > + } else if (quote == cmd[i]) { > + argv << lamMid(); > + quote = 0; > + progress = ++i; > + } > + } > + } > + > + argv << cmd.right(size - progress).split(" ", opt); > + > + return argv; > +} I still find the above hard to read, but so be it ;-) Anyway, not quite yet. I just noticed that if I do: echo "this \" is \" a \"test" The output has: ("echo", "this \" is \" a \"test") We don't want to keep the backslash here. We want to remove it before passing it as an argument. The above should be: ("echo", "this " is " a "test") (thinking that you put in the outside quotes. In other words, if I have: echo "hello \"there\"" We should break that up into: arg0=echo arg1=hello "there" -- Steve