aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2017-03-06 16:16:56 -0800
committerAlexander Karatarakis <alkarata@microsoft.com>2017-03-06 16:18:24 -0800
commit3eb0526468d07824900c462ccfacdeffd7fa1969 (patch)
treed184427313467d92788b99d27d65064e890f197b
parent7f3153bd62a24b1235a98d68d9aac1b00ba1228f (diff)
downloadvcpkg-3eb0526468d07824900c462ccfacdeffd7fa1969.tar.gz
vcpkg-3eb0526468d07824900c462ccfacdeffd7fa1969.zip
Properly handle spaces in path when calling powershell script
-rw-r--r--toolsrc/include/vcpkg_System.h4
-rw-r--r--toolsrc/src/vcpkg_Environment.cpp5
-rw-r--r--toolsrc/src/vcpkg_System.cpp11
3 files changed, 17 insertions, 3 deletions
diff --git a/toolsrc/include/vcpkg_System.h b/toolsrc/include/vcpkg_System.h
index a414ba0d4..14f39ca40 100644
--- a/toolsrc/include/vcpkg_System.h
+++ b/toolsrc/include/vcpkg_System.h
@@ -28,6 +28,10 @@ namespace vcpkg::System
return cmd_execute_and_capture_output(cmd_line.c_str());
}
+ std::wstring create_powershell_script_cmd(const fs::path& script_path);
+
+ std::wstring create_powershell_script_cmd(const fs::path& script_path, const std::wstring& args);
+
enum class color
{
success = 10,
diff --git a/toolsrc/src/vcpkg_Environment.cpp b/toolsrc/src/vcpkg_Environment.cpp
index 94a672e2a..93953f92b 100644
--- a/toolsrc/src/vcpkg_Environment.cpp
+++ b/toolsrc/src/vcpkg_Environment.cpp
@@ -43,8 +43,7 @@ namespace vcpkg::Environment
static std::wstring create_default_install_cmd(const vcpkg_paths& paths, const std::wstring& tool_name)
{
const fs::path script = paths.scripts / "fetchDependency.ps1";
- // TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned
- return Strings::wformat(LR"(powershell -ExecutionPolicy Bypass "%s" -Dependency %s)", script.native(), tool_name);
+ return System::create_powershell_script_cmd(script, Strings::wformat(L"-Dependency %s", tool_name));
}
void ensure_git_on_path(const vcpkg_paths& paths)
@@ -103,7 +102,7 @@ namespace vcpkg::Environment
static std::vector<std::string> get_VS2017_installation_instances(const vcpkg_paths& paths)
{
const fs::path script = paths.scripts / "findVisualStudioInstallationInstances.ps1";
- const std::wstring cmd = Strings::wformat(L"powershell -ExecutionPolicy Bypass %s", script.native());
+ const std::wstring cmd = System::create_powershell_script_cmd(script);
System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd);
Checks::check_exit(ec_data.exit_code == 0, "Could not run script to detect VS 2017 instances");
return Strings::split(ec_data.output, "\n");
diff --git a/toolsrc/src/vcpkg_System.cpp b/toolsrc/src/vcpkg_System.cpp
index 679318768..9609d819b 100644
--- a/toolsrc/src/vcpkg_System.cpp
+++ b/toolsrc/src/vcpkg_System.cpp
@@ -49,6 +49,17 @@ namespace vcpkg::System
return { ec, output };
}
+ std::wstring create_powershell_script_cmd(const fs::path& script_path)
+ {
+ return create_powershell_script_cmd(script_path, L"");
+ }
+
+ std::wstring create_powershell_script_cmd(const fs::path& script_path, const std::wstring& args)
+ {
+ // TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned
+ return Strings::wformat(LR"(powershell -ExecutionPolicy Bypass -Command "& {& '%s' %s}")", script_path.native(), args);
+ }
+
void print(const char* message)
{
fputs(message, stdout);