diff mbox series

[v2,3/3] kernel-shark: Add quotation marks parsing example/test

Message ID 20190918142319.11821-4-y.karadz@gmail.com (mailing list archive)
State Accepted
Headers show
Series Support "shell quoting" in the Record dialog | expand

Commit Message

Yordan Karadzhov Sept. 18, 2019, 2:23 p.m. UTC
The example implements a small GUI that executes shell commands.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 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

Comments

Steven Rostedt Sept. 19, 2019, 11:12 p.m. UTC | #1
On Wed, 18 Sep 2019 17:23:19 +0300
"Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:

> The example implements a small GUI that executes shell commands.
> 
> Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>

The testing on this seems to do what I think it should do.

I did modify it with this change, to get rid of the "Unknown error"
message on success. Care to send a v3?

-- Steve

diff --git a/kernel-shark/examples/cmd_split.cpp b/kernel-shark/examples/cmd_split.cpp
index ac688442..b8cc1b59 100644
--- a/kernel-shark/examples/cmd_split.cpp
+++ b/kernel-shark/examples/cmd_split.cpp
@@ -39,9 +39,10 @@ int main(int argc, char **argv)
 			proc.start();
 			proc.waitForFinished();
 
-			cout << proc.errorString().toStdString()
-			     << endl
-			     << proc.readAllStandardError().toStdString()
+			if (proc.exitCode())
+				cout << proc.errorString().toStdString() << endl;
+
+			cout << proc.readAllStandardError().toStdString()
 			     << endl
 			     << proc.readAllStandardOutput().toStdString()
 			     << endl;
Yordan Karadzhov Sept. 20, 2019, 9:50 a.m. UTC | #2
On 20.09.19 г. 2:12 ч., Steven Rostedt wrote:
> On Wed, 18 Sep 2019 17:23:19 +0300
> "Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:
> 
>> The example implements a small GUI that executes shell commands.
>>
>> Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
> 
> The testing on this seems to do what I think it should do.
> 
> I did modify it with this change, to get rid of the "Unknown error"
> message on success. Care to send a v3?

I don't care, just get it upstream.

Thanks!
Yordan

> 
> -- Steve
> 
> diff --git a/kernel-shark/examples/cmd_split.cpp b/kernel-shark/examples/cmd_split.cpp
> index ac688442..b8cc1b59 100644
> --- a/kernel-shark/examples/cmd_split.cpp
> +++ b/kernel-shark/examples/cmd_split.cpp
> @@ -39,9 +39,10 @@ int main(int argc, char **argv)
>   			proc.start();
>   			proc.waitForFinished();
>   
> -			cout << proc.errorString().toStdString()
> -			     << endl
> -			     << proc.readAllStandardError().toStdString()
> +			if (proc.exitCode())
> +				cout << proc.errorString().toStdString() << endl;
> +
> +			cout << proc.readAllStandardError().toStdString()
>   			     << endl
>   			     << proc.readAllStandardOutput().toStdString()
>   			     << endl;
>
diff mbox series

Patch

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@gmail.com>
+ */
+
+// 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;
+}