File: testexternalcommand.cpp

package info (click to toggle)
kpmcore 24.12.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,696 kB
  • sloc: cpp: 20,700; sh: 22; makefile: 7
file content (59 lines) | stat: -rw-r--r-- 1,358 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
54
55
56
57
58
59
/*
    SPDX-FileCopyrightText: 2018 Andrius Štikonas <andrius@stikonas.eu>
    SPDX-FileCopyrightText: 2019 Shubham Jangra <aryan100jangid@gmail.com>
    SPDX-FileCopyrightText: 2019 Albert Astals Cid <aacid@kde.org>

    SPDX-License-Identifier: GPL-3.0-or-later
*/


#include "helpers.h"
#include "backend/corebackendmanager.h"
#include "util/externalcommand.h"

#include <QCoreApplication>
#include <QDebug>
#include <QThread>

class runcmd : public QThread
{
    public:
    void run() override
    {
        ExternalCommand blkidCmd(QStringLiteral("blkid"), {});

        // ExternalCommadHelper will refuse to run this or any other command which is not whitelisted.
        // See src/util/externalcommand_whitelist.h for whitelisted commands.
        blkidCmd.run();
        qDebug().noquote() << blkidCmd.output();
    }
};

class runcmd2 : public QThread
{
    public:
    void run() override
    {
        ExternalCommand lsblkCmd(QStringLiteral("lsblk"), { QStringLiteral("--nodeps"), QStringLiteral("--json") });
        lsblkCmd.run();
        qDebug().noquote() << lsblkCmd.output();
    }
};


int main( int argc, char **argv )
{
    QCoreApplication app(argc, argv);
    KPMCoreInitializer i(QStringLiteral("pmsfdiskbackendplugin"));

    runcmd a;
    runcmd2 b;

    a.start();
    a.wait();

    b.start();
    b.wait();

    return 0;
}