Index: /trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp	(revision 35540)
+++ /trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp	(revision 35541)
@@ -317,5 +317,4 @@
     bool fWaitForStdErr = false;
     bool fVerbose = false;
-    bool fTimeout = false;
 
     int vrc = VINF_SUCCESS;
@@ -374,5 +373,4 @@
             case 't': /* Timeout */
                 u32TimeoutMS = ValueUnion.u32;
-                fTimeout = true;
                 break;
 
@@ -461,5 +459,5 @@
             if (fWaitForExit)
             {
-                if (fTimeout)
+                if (u32TimeoutMS) /* Wait with a certain timeout. */
                 {
                     /* Calculate timeout value left after process has been started.  */
@@ -468,7 +466,6 @@
                     if (u32TimeoutMS > u64Elapsed)
                     {
-                        u32TimeoutMS -= (uint32_t)u64Elapsed;
                         if (fVerbose)
-                            RTPrintf("Waiting for process to exit (%ums left) ...\n", u32TimeoutMS);
+                            RTPrintf("Waiting for process to exit (%ums left) ...\n", u32TimeoutMS - u64Elapsed);
                     }
                     else
@@ -478,5 +475,5 @@
                     }
                 }
-                else if (fVerbose)
+                else if (fVerbose) /* Wait forever. */
                     RTPrintf("Waiting for process to exit ...\n");
 
@@ -505,13 +502,11 @@
                         || fWaitForStdErr)
                     {
-                        /** @todo r=bird: Why use u32TimeoutMS here?  */
                         rc = guest->GetProcessOutput(uPID, 0 /* aFlags */,
-                                                     u32TimeoutMS, _64K, ComSafeArrayAsOutParam(aOutputData));
+                                                     RT_MAX(0, u32TimeoutMS - (RTTimeMilliTS() - u64StartMS)) /* Timeout in ms */,
+                                                     _64K, ComSafeArrayAsOutParam(aOutputData));
                         if (FAILED(rc))
                         {
                             vrc = ctrlPrintError(guest, COM_IIDOF(IGuest));
-
                             cbOutputData = 0;
-                            fCompleted = true; /* rc contains a failure, so we'll go into aborted state down below. */
                         }
                         else
@@ -541,19 +536,8 @@
                         }
                     }
-                    if (cbOutputData <= 0) /* No more output data left? */
-                    {
-                        if (fCompleted)
-                            break;
-
-                        /** @todo r=bird: Why only apply the timeout here?
-                         *        Shouldn't it time out regardless of
-                         *        whether there is more output or not? */
-                        if (   fTimeout
-                            && RTTimeMilliTS() - u64StartMS > u32TimeoutMS + 5000)
-                        {
-                            progress->Cancel();
-                            break;
-                        }
-                    }
+
+                    /* No more output data left? Then wait a little while ... */
+                    if (cbOutputData <= 0)
+                        progress->WaitForCompletion(1 /* ms */);
 
                     /* Process async cancelation */
@@ -574,6 +558,11 @@
                     }
 
-                    /* Make sure the loop is not too tight. */
-                    RTThreadYield();
+                    /* Did we run out of time? */
+                    if (   u32TimeoutMS
+                        && RTTimeMilliTS() - u64StartMS > u32TimeoutMS)
+                    {
+                        progress->Cancel();
+                        break;
+                    }
                 }
 
