Skip to content

Commit 380eb91

Browse files
committed
fix(deploy): make command capture portable on Windows
1 parent ce5184c commit 380eb91

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

src/commands/deploy/DeployRunner.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@
1313
#include <vix/cli/commands/deploy/DeployRunner.hpp>
1414
#include <vix/cli/commands/deploy/DeployOutput.hpp>
1515

16-
#include <cstdlib>
17-
#include <iostream>
18-
#include <string>
1916
#include <array>
2017
#include <cstdio>
18+
#include <cstdlib>
19+
#include <iostream>
2120
#include <memory>
2221
#include <optional>
22+
#include <string>
23+
24+
#if defined(_WIN32)
25+
#define VIX_CLI_POPEN _popen
26+
#define VIX_CLI_PCLOSE _pclose
27+
#else
28+
#define VIX_CLI_POPEN popen
29+
#define VIX_CLI_PCLOSE pclose
30+
#endif
2331

2432
namespace vix::commands::deploy::runner
2533
{
@@ -58,14 +66,16 @@ namespace vix::commands::deploy::runner
5866
std::array<char, 2048> buffer{};
5967
std::string output;
6068

61-
std::unique_ptr<FILE, decltype(&pclose)> pipe(
62-
popen(cmd.c_str(), "r"),
63-
pclose);
69+
using PipeCloser = int (*)(FILE *);
70+
71+
std::unique_ptr<FILE, PipeCloser> pipe(
72+
VIX_CLI_POPEN(cmd.c_str(), "r"),
73+
VIX_CLI_PCLOSE);
6474

6575
if (!pipe)
6676
return std::nullopt;
6777

68-
while (fgets(buffer.data(), static_cast<int>(buffer.size()), pipe.get()) != nullptr)
78+
while (std::fgets(buffer.data(), static_cast<int>(buffer.size()), pipe.get()) != nullptr)
6979
output += buffer.data();
7080

7181
while (!output.empty() &&

0 commit comments

Comments
 (0)