Skip to content

Commit fc4bb9d

Browse files
committed
desktop_utils.exe --run supports passing command line parameters. Fixes #7
1 parent f226b5a commit fc4bb9d

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

desktop_utils/desktop.cpp

+22-5
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,43 @@ PROCESS_INFORMATION Desktop::createProcess(
5858
PROCESS_INFORMATION pi;
5959
memset(&pi, 0, sizeof(pi));
6060

61-
bo::shared_ptr<wchar_t []> cmdLineTmp;
62-
if (!cmdLine.empty()) {
61+
bo::movelib::unique_ptr<wchar_t []> cmdLineTmp;
62+
bo::movelib::unique_ptr<wchar_t []> appNameTmp;
63+
64+
if (!appName.empty() && !cmdLine.empty()) {
6365
wstring tmp = bo::from_utf8(appName + " " + cmdLine);
6466

6567
cmdLineTmp.reset(new wchar_t[tmp.size()+1]);
6668
memmove(cmdLineTmp.get(), tmp.c_str(), tmp.size()*sizeof(wchar_t));
6769
cmdLineTmp[tmp.size()] = 0;
6870
}
71+
else if (!cmdLine.empty()) {
72+
wstring tmp = bo::from_utf8(cmdLine);
73+
74+
cmdLineTmp.reset(new wchar_t[tmp.size()+1]);
75+
memmove(cmdLineTmp.get(), tmp.c_str(), tmp.size()*sizeof(wchar_t));
76+
cmdLineTmp[tmp.size()] = 0;
77+
}
78+
79+
if (!appName.empty()) {
80+
wstring tmp = bo::from_utf8(appName);
81+
82+
appNameTmp.reset(new wchar_t[tmp.size()+1]);
83+
memmove(appNameTmp.get(), tmp.c_str(), tmp.size()*sizeof(wchar_t));
84+
appNameTmp[tmp.size()] = 0;
85+
}
6986

7087
BOOL created = CreateProcess(
71-
bo::from_utf8(appName).c_str(),
88+
appNameTmp.get(),
7289
cmdLineTmp.get(),
7390
NULL, NULL, FALSE, processCreationFlags, NULL, NULL,
7491
&si, &pi);
7592

7693
if (created == FALSE)
7794
throw DesktopError(
7895
bo::format(
79-
"Could not create the '%1%' process in the '%2%' desktop!")
80-
% appName
96+
"Could not run the '%1%' command in the '%2%' desktop!")
97+
% (appName.empty() ? bo::to_utf8(cmdLineTmp.get()) : appName.c_str())
8198
% desktopName);
8299

83100
return pi;

desktop_utils/desktop_utils.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ ParseStatus parseCommandLine(int argc, _TCHAR *argv[]) {
7878
cout << header << endl << endl
7979
<< "* Available desktops:" << endl;
8080

81-
for (string desktop : Desktop::desktops())
81+
for (auto desktop : Desktop::desktops())
8282
cout << desktop << endl;
83-
83+
8484
return ParseStatus::EXIT_0;
8585
}
8686

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

136136
Desktop::createProcess(
137137
desktopName,
138+
"",
138139
headlessCmd);
139140
}
140141
catch (runtime_error &e) {

desktop_utils/stdafx.h

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <boost/program_options.hpp>
1818
#include <boost/smart_ptr.hpp>
19+
#include <boost/move/unique_ptr.hpp>
1920
#include <boost/format.hpp>
2021
#include <boost/tuple/tuple.hpp>
2122

0 commit comments

Comments
 (0)