diff --git a/tests/runtests.pl b/tests/runtests.pl
index a2af5c94455a296d4e24c165b05c9bd1cad0a756..8de3c0690f19715e6e6abb9af76c495a0c79c6ab 100755
--- a/tests/runtests.pl
+++ b/tests/runtests.pl
@@ -1013,9 +1013,6 @@ sub singletest {
 
         $cmdargs .= " <$stdinfile";
     }
-    if($valgrind) {
-        $cmdargs .= " 3>log/valgrind$testnum";
-    }
     my $CMDLINE;
 
     if(!$tool) {
@@ -1026,6 +1023,10 @@ sub singletest {
         $DBGCURL=$CMDLINE;
     }
 
+    if($valgrind) {
+        $CMDLINE = "exec 3>log/valgrind$testnum && $CMDLINE";
+    }
+
     $CMDLINE .= "$cmdargs >>$STDOUT 2>>$STDERR";
 
     if($verbose) {