6 #include <QStringBuilder>
25 PROCESS_INFORMATION processInfo;
26 memset(&processInfo, 0,
sizeof(processInfo));
28 STARTUPINFO startupInfo;
29 memset(&startupInfo, 0,
sizeof(startupInfo));
30 startupInfo.cb =
sizeof(startupInfo);
32 QString command =
'"' % QString(program).replace(
'/',
'\\') %
'"';
33 if (!arguments.isEmpty()) { command +=
" \"" % arguments.join(
"\" \"").replace(
'/',
'\\') %
'"'; }
36 flags |= NORMAL_PRIORITY_CLASS;
37 flags |= CREATE_UNICODE_ENVIRONMENT;
38 flags |= CREATE_NEW_CONSOLE;
40 Q_ASSERT(command.length() <= MAX_PATH);
41 std::array<WCHAR, MAX_PATH> wszCommandLine = { {} };
42 command.toWCharArray(wszCommandLine.data());
44 int result = CreateProcess(
nullptr, wszCommandLine.data(),
nullptr,
nullptr, inherit, flags,
nullptr,
nullptr,
45 &startupInfo, &processInfo);
49 CLogMessage(
static_cast<CProcessCtrl *
>(
nullptr)).warning(u
"Failed to start %1: %2")
50 << program << GetLastError();
54 CloseHandle(processInfo.hProcess);
55 CloseHandle(processInfo.hThread);
62 return QProcess::startDetached(program, arguments);
69 else {
return QProcess::startDetached(program, arguments); }
CProcessCtrl(QObject *parent=nullptr)
Constructor.
static bool startDetached(const QString &program, const QStringList &arguments, bool withConsoleWindow)
Start a programm detached and without any console window.
Free functions in swift::misc.
bool startDetachedWithConsoleWindow(const QString &program, const QStringList &arguments)
unsigned long DWORD
Fake Windows DWORD.