Hi Yordan! Thanks for the quick work on this issue :) On Tue, Aug 27 16:14, Yordan Karadzhov (VMware) wrote: > Shell-like parsing of quotation marks in the content of the "Command" > field of the "Record" dialog will give more options to the users. > For example, now we can trace > > python -c 'print("hello world")' > > Suggested-by: Stephen Brennan <stephen@xxxxxxxxxx> > Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204679 > Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx> > --- > kernel-shark/src/KsCaptureDialog.cpp | 38 ++++++++++++++++++++++++++-- > 1 file changed, 36 insertions(+), 2 deletions(-) > > diff --git a/kernel-shark/src/KsCaptureDialog.cpp b/kernel-shark/src/KsCaptureDialog.cpp > index dc1e9b2..b3393b6 100644 > --- a/kernel-shark/src/KsCaptureDialog.cpp > +++ b/kernel-shark/src/KsCaptureDialog.cpp > @@ -157,7 +157,9 @@ KsCaptureControl::KsCaptureControl(QWidget *parent) > */ > QStringList KsCaptureControl::getArgs() > { > + QString::SplitBehavior opt = QString::SkipEmptyParts; > QStringList argv; > + QString cmdTmp; > > argv << "record"; > > @@ -170,7 +172,36 @@ QStringList KsCaptureControl::getArgs() > argv << _eventsWidget.getCheckedEvents(true); > > argv << "-o" << outputFileName(); > - argv << _commandLineEdit.text().split(" "); > + > + cmdTmp = _commandLineEdit.text(); > + if (!cmdTmp.contains('\'') && !cmdTmp.contains('\"')) { > + /* Split all command line arguments. */ > + argv << cmdTmp.split(" ", opt); > + } else { > + int iOpenQuots, iCloseQuots, size = cmdTmp.size(); > + int iSingleQuots = (cmdTmp.count('\'') == 2) ? cmdTmp.indexOf('\'') : size; > + int iDoubleQuots = (cmdTmp.count('\"') == 2) ? cmdTmp.indexOf('\"') : size; > + > + if (iSingleQuots < iDoubleQuots) { > + iOpenQuots = iSingleQuots; > + iCloseQuots = cmdTmp.lastIndexOf('\'') + 1; > + } else if (iDoubleQuots < iSingleQuots) { > + iOpenQuots = iDoubleQuots; > + iCloseQuots = cmdTmp.lastIndexOf('\"') + 1; > + } else { > + emit print("\nERROR: Unable to parse the command."); > + return {}; > + } > + > + /* Split the arguments. */ > + argv << cmdTmp.left(iOpenQuots).split(" ", opt); > + > + /* Everything in between the quotation marks goes in one piece. */ > + argv << cmdTmp.mid(iOpenQuots, iCloseQuots - iOpenQuots); > + > + /* Split the rest of the arguments. */ > + argv << cmdTmp.right(size - iCloseQuots).split(" ", opt); > + } It strikes me that this explicitly supports only a single set of quotes. This sort of behavior would be pretty surprising for people expecting shell quote support, and for people expecting just splitting on spaces. I looked and couldn't really find any Qt utility for properly parsing shell quoting (similar to python's shlex module). I totally get that it's a lot of work to implement a correct shell quoting parser. Maybe a compromise would be to add a checkbox to the capture dialog, which tells kernel-shark to pass the entire textbox contents, unmodified, to the shell implementation on the system. So, my example of: python -c 'print("hello world")' Would get put into the third argument of the command: /bin/sh -c INSERT_TEXTBOX_CONTENTS_HERE Then you could rely on /bin/sh doing the parsing for you. The downside is that it adds a whole new process. But you can't always get everything in life, right? Hope this was helpful! Stephen