aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/vcpkg_System.cpp
diff options
context:
space:
mode:
authorRobert Schumacher <roschuma@microsoft.com>2017-02-21 13:39:36 -0800
committerGitHub <noreply@github.com>2017-02-21 13:39:36 -0800
commit7d4df89c1dfff0b2bad0165ac4579f6352935a94 (patch)
tree8b87d29fb74fb24984d5aff9b021f14d95afb5ab /toolsrc/src/vcpkg_System.cpp
parentd9462fdf490d3396cac58b1a935b1b8a982b3a72 (diff)
parentb921dce5fc17bd4c1c206b79eb0a7b8758dcf5bf (diff)
downloadvcpkg-7d4df89c1dfff0b2bad0165ac4579f6352935a94.tar.gz
vcpkg-7d4df89c1dfff0b2bad0165ac4579f6352935a94.zip
Merge branch 'master' into master
Diffstat (limited to 'toolsrc/src/vcpkg_System.cpp')
-rw-r--r--toolsrc/src/vcpkg_System.cpp31
1 files changed, 21 insertions, 10 deletions
diff --git a/toolsrc/src/vcpkg_System.cpp b/toolsrc/src/vcpkg_System.cpp
index 754a26741..90ec9c99c 100644
--- a/toolsrc/src/vcpkg_System.cpp
+++ b/toolsrc/src/vcpkg_System.cpp
@@ -14,6 +14,9 @@ namespace vcpkg::System
int cmd_execute(const wchar_t* cmd_line)
{
+ // Flush cout before launching external process
+ std::cout << std::flush;
+
// Basically we are wrapping it in quotes
const std::wstring& actual_cmd_line = Strings::wformat(LR"###("%s")###", cmd_line);
int exit_code = _wsystem(actual_cmd_line.c_str());
@@ -22,6 +25,9 @@ namespace vcpkg::System
exit_code_and_output cmd_execute_and_capture_output(const wchar_t* cmd_line)
{
+ // Flush cout before launching external process
+ std::cout << std::flush;
+
const std::wstring& actual_cmd_line = Strings::wformat(LR"###("%s")###", cmd_line);
std::string output;
@@ -29,7 +35,7 @@ namespace vcpkg::System
auto pipe = _wpopen(actual_cmd_line.c_str(), L"r");
if (pipe == nullptr)
{
- return {1, output};
+ return { 1, output };
}
while (fgets(buf, 1024, pipe))
{
@@ -37,10 +43,10 @@ namespace vcpkg::System
}
if (!feof(pipe))
{
- return {1, output};
+ return { 1, output };
}
auto ec = _pclose(pipe);
- return {ec, output};
+ return { ec, output };
}
void print(const char* message)
@@ -62,7 +68,7 @@ namespace vcpkg::System
GetConsoleScreenBufferInfo(hConsole, &consoleScreenBufferInfo);
auto original_color = consoleScreenBufferInfo.wAttributes;
- SetConsoleTextAttribute(hConsole, static_cast<int>(c) | (original_color & 0xF0));
+ SetConsoleTextAttribute(hConsole, static_cast<WORD>(c) | (original_color & 0xF0));
std::cout << message;
SetConsoleTextAttribute(hConsole, original_color);
}
@@ -73,17 +79,22 @@ namespace vcpkg::System
std::cout << "\n";
}
- std::wstring wdupenv_str(const wchar_t* varname) noexcept
+ optional<std::wstring> get_environmental_variable(const wchar_t* varname) noexcept
{
- std::wstring ret;
wchar_t* buffer;
_wdupenv_s(&buffer, nullptr, varname);
- if (buffer != nullptr)
+
+ if (buffer == nullptr)
{
- ret = buffer;
- free(buffer);
+ return nullptr;
}
- return ret;
+ std::unique_ptr<wchar_t, void(__cdecl *)(void*)> bufptr(buffer, free);
+ return std::make_unique<std::wstring>(buffer);
+ }
+
+ void set_environmental_variable(const wchar_t* varname, const wchar_t* varvalue) noexcept
+ {
+ _wputenv_s(varname, varvalue);
}
void Stopwatch2::start()