The example implements a small GUI that executes shell commands. Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx> --- kernel-shark/examples/CMakeLists.txt | 4 +++ kernel-shark/examples/cmd_split.cpp | 52 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 kernel-shark/examples/cmd_split.cpp diff --git a/kernel-shark/examples/CMakeLists.txt b/kernel-shark/examples/CMakeLists.txt index e16216e..35e6b1e 100644 --- a/kernel-shark/examples/CMakeLists.txt +++ b/kernel-shark/examples/CMakeLists.txt @@ -23,3 +23,7 @@ target_link_libraries(dplot kshark-plot) message(STATUS "widgetdemo") add_executable(widgetdemo widgetdemo.cpp) target_link_libraries(widgetdemo kshark-gui) + +message(STATUS "cmd_split") +add_executable(cmd_split cmd_split.cpp) +target_link_libraries(cmd_split kshark-gui) diff --git a/kernel-shark/examples/cmd_split.cpp b/kernel-shark/examples/cmd_split.cpp new file mode 100644 index 0000000..ac68844 --- /dev/null +++ b/kernel-shark/examples/cmd_split.cpp @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (C) 2017 VMware Inc, Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx> + */ + +// C++ +#include<iostream> +using namespace std; + +// Qt +#include <QtWidgets> + +// KernelShark +#include "KsUtils.hpp" + +int main(int argc, char **argv) +{ + QString text = "echo \"I want \\\" here\" \\\n \"and \\\' here\""; + QApplication a(argc, argv); + QStringList argList; + bool ok = true; + QProcess proc; + + while (ok) { + text = QInputDialog::getMultiLineText(nullptr, + "Shell quoting test", + "Shell input:", + text, + &ok); + + if (ok) { + argList = KsUtils::splitArguments(text); + qInfo() << argList; + + proc.setProgram(argList.takeFirst()); + proc.setArguments(argList); + + proc.start(); + proc.waitForFinished(); + + cout << proc.errorString().toStdString() + << endl + << proc.readAllStandardError().toStdString() + << endl + << proc.readAllStandardOutput().toStdString() + << endl; + } + } + + return 0; +} -- 2.20.1