File: cmd_split.cpp

package info (click to toggle)
kernelshark 2.2.1-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,744 kB
  • sloc: cpp: 12,517; ansic: 11,521; makefile: 89; sh: 88
file content (53 lines) | stat: -rw-r--r-- 1,028 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// 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();

			if (proc.exitCode())
				cout << proc.errorString().toStdString() << endl;

			cout << proc.readAllStandardError().toStdString()
			     << endl
			     << proc.readAllStandardOutput().toStdString()
			     << endl;
		}
	}

	return 0;
}