Skip to content

Commit

Permalink
desktop_utils.exe --run supports passing command line parameters. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kybu committed Dec 5, 2015
1 parent f226b5a commit fc4bb9d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
27 changes: 22 additions & 5 deletions desktop_utils/desktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,43 @@ PROCESS_INFORMATION Desktop::createProcess(
PROCESS_INFORMATION pi;
memset(&pi, 0, sizeof(pi));

bo::shared_ptr<wchar_t []> cmdLineTmp;
if (!cmdLine.empty()) {
bo::movelib::unique_ptr<wchar_t []> cmdLineTmp;
bo::movelib::unique_ptr<wchar_t []> appNameTmp;

if (!appName.empty() && !cmdLine.empty()) {
wstring tmp = bo::from_utf8(appName + " " + cmdLine);

cmdLineTmp.reset(new wchar_t[tmp.size()+1]);
memmove(cmdLineTmp.get(), tmp.c_str(), tmp.size()*sizeof(wchar_t));
cmdLineTmp[tmp.size()] = 0;
}
else if (!cmdLine.empty()) {
wstring tmp = bo::from_utf8(cmdLine);

cmdLineTmp.reset(new wchar_t[tmp.size()+1]);
memmove(cmdLineTmp.get(), tmp.c_str(), tmp.size()*sizeof(wchar_t));
cmdLineTmp[tmp.size()] = 0;
}

if (!appName.empty()) {
wstring tmp = bo::from_utf8(appName);

appNameTmp.reset(new wchar_t[tmp.size()+1]);
memmove(appNameTmp.get(), tmp.c_str(), tmp.size()*sizeof(wchar_t));
appNameTmp[tmp.size()] = 0;
}

BOOL created = CreateProcess(
bo::from_utf8(appName).c_str(),
appNameTmp.get(),
cmdLineTmp.get(),
NULL, NULL, FALSE, processCreationFlags, NULL, NULL,
&si, &pi);

if (created == FALSE)
throw DesktopError(
bo::format(
"Could not create the '%1%' process in the '%2%' desktop!")
% appName
"Could not run the '%1%' command in the '%2%' desktop!")
% (appName.empty() ? bo::to_utf8(cmdLineTmp.get()) : appName.c_str())
% desktopName);

return pi;
Expand Down
5 changes: 3 additions & 2 deletions desktop_utils/desktop_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ ParseStatus parseCommandLine(int argc, _TCHAR *argv[]) {
cout << header << endl << endl
<< "* Available desktops:" << endl;

for (string desktop : Desktop::desktops())
for (auto desktop : Desktop::desktops())
cout << desktop << endl;

return ParseStatus::EXIT_0;
}

Expand Down Expand Up @@ -135,6 +135,7 @@ int _tmain(int argc, _TCHAR* argv[]) {

Desktop::createProcess(
desktopName,
"",
headlessCmd);
}
catch (runtime_error &e) {
Expand Down
1 change: 1 addition & 0 deletions desktop_utils/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <boost/program_options.hpp>
#include <boost/smart_ptr.hpp>
#include <boost/move/unique_ptr.hpp>
#include <boost/format.hpp>
#include <boost/tuple/tuple.hpp>

Expand Down

0 comments on commit fc4bb9d

Please sign in to comment.