Skip to content

Commit 18f6604

Browse files
authored
[wasm-reduce] Get the return code from pclose (#7624)
Rather than executing the reduction command twice for every candidate, once to get the return code and once to capture stdout, just run it once and capture both.
1 parent 08428b3 commit 18f6604

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

src/tools/wasm-reduce.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ struct ProgramResult {
185185
void getFromExecution(std::string command) {
186186
Timer timer;
187187
timer.start();
188-
// do this using just core stdio.h and stdlib.h, for portability
189-
// sadly this requires two invokes
190-
code = system(("timeout " + std::to_string(timeout) + "s " + command +
191-
" > /dev/null 2> /dev/null")
192-
.c_str());
193188
const int MAX_BUFFER = 1024;
194189
char buffer[MAX_BUFFER];
195190
FILE* stream = popen(
@@ -199,7 +194,7 @@ struct ProgramResult {
199194
while (fgets(buffer, MAX_BUFFER, stream) != NULL) {
200195
output.append(buffer);
201196
}
202-
pclose(stream);
197+
code = pclose(stream);
203198
timer.stop();
204199
time = timer.getTotal() / 2;
205200
}

0 commit comments

Comments
 (0)