summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qprocess.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io/qprocess.cpp')
-rw-r--r--src/corelib/io/qprocess.cpp68
1 files changed, 40 insertions, 28 deletions
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp
index 49e0847d44..4500467ac2 100644
--- a/src/corelib/io/qprocess.cpp
+++ b/src/corelib/io/qprocess.cpp
@@ -216,7 +216,7 @@ void QProcessEnvironmentPrivate::insert(const QProcessEnvironmentPrivate &other)
environment variables to be removed.
*/
QProcessEnvironment::QProcessEnvironment()
- : d(0)
+ : d(nullptr)
{
}
@@ -436,18 +436,18 @@ void QProcessPrivate::Channel::clear()
case PipeSource:
Q_ASSERT(process);
process->stdinChannel.type = Normal;
- process->stdinChannel.process = 0;
+ process->stdinChannel.process = nullptr;
break;
case PipeSink:
Q_ASSERT(process);
process->stdoutChannel.type = Normal;
- process->stdoutChannel.process = 0;
+ process->stdoutChannel.process = nullptr;
break;
}
type = Normal;
file.clear();
- process = 0;
+ process = nullptr;
}
/*!
@@ -869,8 +869,8 @@ QProcessPrivate::QProcessPrivate()
sequenceNumber = 0;
exitCode = 0;
exitStatus = QProcess::NormalExit;
- startupSocketNotifier = 0;
- deathNotifier = 0;
+ startupSocketNotifier = nullptr;
+ deathNotifier = nullptr;
childStartedPipe[0] = INVALID_Q_PIPE;
childStartedPipe[1] = INVALID_Q_PIPE;
forkfd = -1;
@@ -924,23 +924,23 @@ void QProcessPrivate::cleanup()
if (stdoutChannel.notifier) {
delete stdoutChannel.notifier;
- stdoutChannel.notifier = 0;
+ stdoutChannel.notifier = nullptr;
}
if (stderrChannel.notifier) {
delete stderrChannel.notifier;
- stderrChannel.notifier = 0;
+ stderrChannel.notifier = nullptr;
}
if (stdinChannel.notifier) {
delete stdinChannel.notifier;
- stdinChannel.notifier = 0;
+ stdinChannel.notifier = nullptr;
}
if (startupSocketNotifier) {
delete startupSocketNotifier;
- startupSocketNotifier = 0;
+ startupSocketNotifier = nullptr;
}
if (deathNotifier) {
delete deathNotifier;
- deathNotifier = 0;
+ deathNotifier = nullptr;
}
closeChannel(&stdoutChannel);
closeChannel(&stderrChannel);
@@ -1229,7 +1229,7 @@ void QProcessPrivate::closeWriteChannel()
#endif
if (stdinChannel.notifier) {
delete stdinChannel.notifier;
- stdinChannel.notifier = 0;
+ stdinChannel.notifier = nullptr;
}
#ifdef Q_OS_WIN
// ### Find a better fix, feeding the process little by little
@@ -2246,8 +2246,16 @@ void QProcessPrivate::start(QIODevice::OpenMode mode)
startProcess();
}
+/*!
+ \since 5.15
+
+ Splits the string \a command into a list of tokens, and returns
+ the list.
-static QStringList parseCombinedArgString(const QString &program)
+ Tokens with spaces can be surrounded by double quotes; three
+ consecutive double quotes represent the quote character itself.
+*/
+QStringList QProcess::splitCommand(QStringView command)
{
QStringList args;
QString tmp;
@@ -2257,13 +2265,13 @@ static QStringList parseCombinedArgString(const QString &program)
// handle quoting. tokens can be surrounded by double quotes
// "hello world". three consecutive double quotes represent
// the quote character itself.
- for (int i = 0; i < program.size(); ++i) {
- if (program.at(i) == QLatin1Char('"')) {
+ for (int i = 0; i < command.size(); ++i) {
+ if (command.at(i) == QLatin1Char('"')) {
++quoteCount;
if (quoteCount == 3) {
// third consecutive quote
quoteCount = 0;
- tmp += program.at(i);
+ tmp += command.at(i);
}
continue;
}
@@ -2272,13 +2280,13 @@ static QStringList parseCombinedArgString(const QString &program)
inQuote = !inQuote;
quoteCount = 0;
}
- if (!inQuote && program.at(i).isSpace()) {
+ if (!inQuote && command.at(i).isSpace()) {
if (!tmp.isEmpty()) {
args += tmp;
tmp.clear();
}
} else {
- tmp += program.at(i);
+ tmp += command.at(i);
}
}
if (!tmp.isEmpty())
@@ -2288,6 +2296,7 @@ static QStringList parseCombinedArgString(const QString &program)
}
/*!
+ \obsolete
\overload
Starts the command \a command in a new process.
@@ -2324,11 +2333,13 @@ static QStringList parseCombinedArgString(const QString &program)
list-based API. In these rare cases you need to use setProgram() and
setNativeArguments() instead of this function.
+ \sa splitCommand()
+
*/
#if !defined(QT_NO_PROCESS_COMBINED_ARGUMENT_START)
void QProcess::start(const QString &command, OpenMode mode)
{
- QStringList args = parseCombinedArgString(command);
+ QStringList args = splitCommand(command);
if (args.isEmpty()) {
Q_D(QProcess);
d->setErrorAndEmit(QProcess::FailedToStart, tr("No program defined"));
@@ -2493,6 +2504,7 @@ int QProcess::execute(const QString &program, const QStringList &arguments)
}
/*!
+ \obsolete
\overload
Starts the program \a command in a new process, waits for it to finish,
@@ -2503,16 +2515,15 @@ int QProcess::execute(const QString &program, const QStringList &arguments)
After the \a command string has been split and unquoted, this function
behaves like the overload which takes the arguments as a string list.
- \sa start()
+ \sa start(), splitCommand()
*/
int QProcess::execute(const QString &command)
{
- QProcess process;
- process.setProcessChannelMode(ForwardedChannels);
- process.start(command);
- if (!process.waitForFinished(-1) || process.error() == FailedToStart)
+ QStringList args = splitCommand(command);
+ if (args.isEmpty())
return -2;
- return process.exitStatus() == QProcess::NormalExit ? process.exitCode() : -1;
+ QString program = args.takeFirst();
+ return execute(program, args);
}
/*!
@@ -2559,6 +2570,7 @@ bool QProcess::startDetached(const QString &program,
}
/*!
+ \obsolete
\overload startDetached()
Starts the command \a command in a new process, and detaches from it.
@@ -2569,11 +2581,11 @@ bool QProcess::startDetached(const QString &program,
After the \a command string has been split and unquoted, this function
behaves like the overload which takes the arguments as a string list.
- \sa start(const QString &command, QIODevice::OpenMode mode)
+ \sa start(const QString &command, QIODevice::OpenMode mode), splitCommand()
*/
bool QProcess::startDetached(const QString &command)
{
- QStringList args = parseCombinedArgString(command);
+ QStringList args = splitCommand(command);
if (args.isEmpty())
return false;
@@ -2617,7 +2629,7 @@ QT_END_INCLUDE_NAMESPACE
QStringList QProcess::systemEnvironment()
{
QStringList tmp;
- char *entry = 0;
+ char *entry = nullptr;
int count = 0;
while ((entry = environ[count++]))
tmp << QString::fromLocal8Bit(entry);