Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
src_corelib_io_qprocess.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4
6{
7
9QProcess builder;
10builder.setProcessChannelMode(QProcess::MergedChannels);
11builder.start("make", QStringList() << "-j2");
12
13if (!builder.waitForFinished())
14 qDebug() << "Make failed:" << builder.errorString();
15else
16 qDebug() << "Make output:" << builder.readAll();
18
19
21QProcess more;
22more.start("more");
23more.write("Text to display");
24more.closeWriteChannel();
25// QProcess will emit readyRead() once "more" starts printing
27
28
32
33
35QProcess process1;
36QProcess process2;
37
38process1.setStandardOutputProcess(&process2);
39
40process1.start("command1");
41process2.start("command2");
43
44
46void runSandboxed(const QString &name, const QStringList &arguments)
47{
48 QProcess proc;
49 proc.setChildProcessModifier([] {
50 // Drop all privileges in the child process, and enter
51 // a chroot jail.
52 ::setgroups(0, nullptr);
53 ::chroot("/run/safedir");
54 ::chdir("/");
55 ::setgid(safeGid);
56 ::setuid(safeUid);
57 ::umask(077);
58 });
59 proc.start(name, arguments);
60 proc.waitForFinished();
61}
63
64
66QProcess process;
67process.startCommand("del /s *.txt");
68// same as process.start("del", QStringList() << "/s" << "*.txt");
69...
71
72
74QProcess process;
75process.startCommand("dir \"My Documents\"");
77
78
80QProcess process;
81process.startCommand("dir \"Epic 12\"\"\" Singles\"");
83
84
86QStringList environment = QProcess::systemEnvironment();
87// environment = {"PATH=/usr/bin:/usr/local/bin",
88// "USER=greg", "HOME=/home/greg"}
90
91}
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QList< QVariant > arguments
QList< QString > QStringList
Constructs a string list that contains the given string, str.
#define qDebug
[1]
Definition qlogging.h:164
GLuint name
void wrapInFunction()
MyCommand * command2
MyCommand * command1
[0]