Support setCreateProcessArgumentsModifier in QProcess:startDetached
Factor out both CreateProcess calls into one function that also calls the modifier callback for the CreateProcessArguments struct. Task-number: QTBUG-57687 Change-Id: I9d2ef4f2d7cd077aa4c3eba926ab4dfb9e570291 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
3cb4bbfc26
commit
b137734e6b
@ -363,6 +363,7 @@ public:
|
||||
bool waitForDeadChild();
|
||||
#endif
|
||||
#ifdef Q_OS_WIN
|
||||
bool callCreateProcess(QProcess::CreateProcessArguments *cpargs);
|
||||
bool drainOutputPipes();
|
||||
void flushPipeWriter();
|
||||
qint64 pipeWriterBytesToWrite() const;
|
||||
|
@ -458,6 +458,16 @@ static QByteArray qt_create_environment(const QProcessEnvironmentPrivate::Hash &
|
||||
return envlist;
|
||||
}
|
||||
|
||||
bool QProcessPrivate::callCreateProcess(QProcess::CreateProcessArguments *cpargs)
|
||||
{
|
||||
if (modifyCreateProcessArgs)
|
||||
modifyCreateProcessArgs(cpargs);
|
||||
return CreateProcess(cpargs->applicationName, cpargs->arguments, cpargs->processAttributes,
|
||||
cpargs->threadAttributes, cpargs->inheritHandles, cpargs->flags,
|
||||
cpargs->environment, cpargs->currentDirectory, cpargs->startupInfo,
|
||||
cpargs->processInformation);
|
||||
}
|
||||
|
||||
void QProcessPrivate::startProcess()
|
||||
{
|
||||
Q_Q(QProcess);
|
||||
@ -516,12 +526,7 @@ void QProcessPrivate::startProcess()
|
||||
nativeWorkingDirectory.isEmpty() ? Q_NULLPTR : (wchar_t*)nativeWorkingDirectory.utf16(),
|
||||
&startupInfo, pid
|
||||
};
|
||||
if (modifyCreateProcessArgs)
|
||||
modifyCreateProcessArgs(&cpargs);
|
||||
success = CreateProcess(cpargs.applicationName, cpargs.arguments, cpargs.processAttributes,
|
||||
cpargs.threadAttributes, cpargs.inheritHandles, cpargs.flags,
|
||||
cpargs.environment, cpargs.currentDirectory, cpargs.startupInfo,
|
||||
cpargs.processInformation);
|
||||
success = callCreateProcess(&cpargs);
|
||||
|
||||
QString errorString;
|
||||
if (!success) {
|
||||
@ -886,10 +891,14 @@ bool QProcessPrivate::startDetached(qint64 *pid)
|
||||
(ulong)CW_USEDEFAULT, (ulong)CW_USEDEFAULT,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
success = CreateProcess(0, (wchar_t*)args.utf16(),
|
||||
0, 0, FALSE, dwCreationFlags, envPtr,
|
||||
workingDirectory.isEmpty() ? 0 : (wchar_t*)workingDirectory.utf16(),
|
||||
&startupInfo, &pinfo);
|
||||
QProcess::CreateProcessArguments cpargs = {
|
||||
nullptr, reinterpret_cast<wchar_t *>(const_cast<ushort *>(args.utf16())),
|
||||
nullptr, nullptr, false, dwCreationFlags, envPtr,
|
||||
workingDirectory.isEmpty()
|
||||
? nullptr : reinterpret_cast<const wchar_t *>(workingDirectory.utf16()),
|
||||
&startupInfo, &pinfo
|
||||
};
|
||||
success = callCreateProcess(&cpargs);
|
||||
|
||||
if (success) {
|
||||
CloseHandle(pinfo.hThread);
|
||||
|
@ -2049,6 +2049,11 @@ void tst_QProcess::detachedProcessParameters()
|
||||
|
||||
QProcess process;
|
||||
process.setProgram(QDir::currentPath() + QLatin1String("/testDetached/testDetached"));
|
||||
#ifdef Q_OS_WIN
|
||||
int modifierCalls = 0;
|
||||
process.setCreateProcessArgumentsModifier(
|
||||
[&modifierCalls] (QProcess::CreateProcessArguments *) { modifierCalls++; });
|
||||
#endif
|
||||
process.setArguments(QStringList(infoFile.fileName()));
|
||||
process.setWorkingDirectory(workingDir);
|
||||
process.setProcessEnvironment(environment);
|
||||
@ -2076,6 +2081,9 @@ void tst_QProcess::detachedProcessParameters()
|
||||
QCOMPARE(actualWorkingDir, workingDir);
|
||||
QCOMPARE(actualPid, pid);
|
||||
QCOMPARE(actualEnvVarValue, envVarValue);
|
||||
#ifdef Q_OS_WIN
|
||||
QCOMPARE(modifierCalls, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QProcess::switchReadChannels()
|
||||
|
Loading…
Reference in New Issue
Block a user