diff --git a/lib/specinfra/backend/exec.rb b/lib/specinfra/backend/exec.rb
index <HASH>..<HASH> 100644
--- a/lib/specinfra/backend/exec.rb
+++ b/lib/specinfra/backend/exec.rb
@@ -122,11 +122,11 @@ module Specinfra
 
           pid = spawn(cmd, :out => out_w, :err => err_w)
 
+          pid, stats = Process.waitpid2(pid)
+
           out_w.close
           err_w.close
 
-          pid, stats = Process.waitpid2(pid)
-
           begin
             quit_w.syswrite 1
           rescue Errno::EPIPE
Close communication pipes after process finished

During process living, those pipes are used.