diff --git a/matlab/dynare.m b/matlab/dynare.m
index c22a5f3c7e76dea22adcc71fae3decf4ba3f5818..b782210872caa61538e714add4f5a3bbc827a18b 100644
--- a/matlab/dynare.m
+++ b/matlab/dynare.m
@@ -254,9 +254,15 @@ else
 end
 
 pTic = tic;
-[status, result] = system(command);
+if preprocessoroutput
+    status = system(command); %immediately flush output
+else
+    [status, result] = system(command); %save output for output in case of failure
+    if status ~= 0 || preprocessoroutput
+        disp(result)
+    end
+end
 if status ~= 0 || preprocessoroutput
-    disp(result)
     pToc = toc(pTic);
     dprintf('Preprocessing time: %s.', dynsec2hms(pToc))
     if nargout