summaryrefslogtreecommitdiff
path: root/src/spawn.cpp
diff options
context:
space:
mode:
authorTannin <devnull@localhost>2014-04-05 15:14:37 +0200
committerTannin <devnull@localhost>2014-04-05 15:14:37 +0200
commitc017f4a0d50b67a44e276bd5ae8929ed3990c62c (patch)
treebe504af55ffc99b657eca9938a4a76864e41454f /src/spawn.cpp
parentb1f1682790072fbfb45bd9eaa3c6890edfb81a22 (diff)
- added buttons to backup and restore the modlist and pluginlist
- replaced boss integration with loot
Diffstat (limited to 'src/spawn.cpp')
-rw-r--r--src/spawn.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/spawn.cpp b/src/spawn.cpp
index b1c5e963..6adafba0 100644
--- a/src/spawn.cpp
+++ b/src/spawn.cpp
@@ -36,10 +36,23 @@ using namespace MOShared;
static const int BUFSIZE = 4096;
-bool spawn(LPCWSTR binary, LPCWSTR arguments, LPCWSTR currentDirectory, bool suspended, HANDLE& processHandle, HANDLE& threadHandle)
+bool spawn(LPCWSTR binary, LPCWSTR arguments, LPCWSTR currentDirectory, bool suspended,
+ HANDLE stdOut, HANDLE stdErr,
+ HANDLE& processHandle, HANDLE& threadHandle)
{
+ BOOL inheritHandles = FALSE;
STARTUPINFO si;
::ZeroMemory(&si, sizeof(si));
+ if (stdOut != INVALID_HANDLE_VALUE) {
+ si.hStdOutput = stdOut;
+ inheritHandles = TRUE;
+ si.dwFlags |= STARTF_USESTDHANDLES;
+ }
+ if (stdErr != INVALID_HANDLE_VALUE) {
+ si.hStdError = stdErr;
+ inheritHandles = TRUE;
+ si.dwFlags |= STARTF_USESTDHANDLES;
+ }
si.cb = sizeof(si);
int length = wcslen(binary) + wcslen(arguments) + 4;
wchar_t *commandLine = NULL;
@@ -74,7 +87,7 @@ bool spawn(LPCWSTR binary, LPCWSTR arguments, LPCWSTR currentDirectory, bool sus
BOOL success = ::CreateProcess(NULL,
commandLine,
NULL, NULL, // no special process or thread attributes
- FALSE, // don't inherit handle
+ inheritHandles, // inherit handles if we plan to use stdout or stderr reroute
suspended ? CREATE_SUSPENDED : 0, // create suspended so I have time to inject the DLL
NULL, // same environment as parent
currentDirectory, // current directory
@@ -95,14 +108,22 @@ bool spawn(LPCWSTR binary, LPCWSTR arguments, LPCWSTR currentDirectory, bool sus
}
-HANDLE startBinary(const QFileInfo &binary, const QString &arguments, const QString& profileName, int logLevel, const QDir &currentDirectory, bool hooked)
+HANDLE startBinary(const QFileInfo &binary,
+ const QString &arguments,
+ const QString& profileName,
+ int logLevel,
+ const QDir &currentDirectory,
+ bool hooked,
+ HANDLE stdOut,
+ HANDLE stdErr)
{
HANDLE processHandle, threadHandle;
std::wstring binaryName = ToWString(QDir::toNativeSeparators(binary.absoluteFilePath()));
std::wstring currentDirectoryName = ToWString(QDir::toNativeSeparators(currentDirectory.absolutePath()));
try {
- if (!spawn(binaryName.c_str(), ToWString(arguments).c_str(), currentDirectoryName.c_str(), hooked, processHandle, threadHandle)) {
+ if (!spawn(binaryName.c_str(), ToWString(arguments).c_str(), currentDirectoryName.c_str(), hooked,
+ stdOut, stdErr, processHandle, threadHandle)) {
reportError(QObject::tr("failed to spawn \"%1\"").arg(binary.fileName()));
return INVALID_HANDLE_VALUE;
}