Skip to content

Commit 5e20980

Browse files
committed
fix regression on windows: modes for popen
1 parent 8c8f846 commit 5e20980

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/vision_process.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,14 @@ namespace vision
157157
#if defined(_WIN64)
158158
#define MAGICK_CONVERT_CMD "magick"
159159
#define MAGICK_IDENTIFY_CMD "magick identify"
160+
#define POPEN_MODE_READ "rb"
161+
#define POPEN_MODE_WRITE "wb"
160162
#else
161163
#define MAGICK_CONVERT_CMD "convert"
162164
#define MAGICK_IDENTIFY_CMD "identify"
165+
#define MAGICK_DISPLAY_CMD "display"
166+
#define POPEN_MODE_READ "r"
167+
#define POPEN_MODE_WRITE "w"
163168
#endif
164169

165170
void image_dimension(const char *fn, int &width, int &height)
@@ -198,7 +203,7 @@ namespace vision
198203

199204
//printf("%s\n", oss.str().c_str());
200205

201-
FILE* pp = popen(oss.str().c_str(), "r");
206+
FILE* pp = popen(oss.str().c_str(), POPEN_MODE_READ);
202207

203208
while (!feof(pp))
204209
{
@@ -736,10 +741,10 @@ namespace vision
736741
int64_t data_cnt = 0;
737742

738743
#if defined(_WIN64)
739-
oss << "magick";
744+
oss << MAGICK_CONVERT_CMD;
740745
const std::string fn = "\"" + utils::tmpname() + ".png\"";
741746
#else
742-
oss << "display";
747+
oss << MAGICK_DISPLAY_CMD;
743748
#endif
744749

745750
switch (fmt)
@@ -763,7 +768,7 @@ namespace vision
763768
oss << " " << fn;
764769
#endif
765770

766-
FILE* pp = popen(oss.str().c_str(), "wb");
771+
FILE* pp = popen(oss.str().c_str(), POPEN_MODE_WRITE);
767772
fwrite(data.data(), 1, data_cnt, pp);
768773
pclose(pp);
769774

0 commit comments

Comments
 (0)