}
          if (ua->api) user->signal(BNET_CMD_BEGIN);
          ok = (*commands[i].func)(ua, ua->cmd);   /* go execute command */
+         if (ua->api) user->signal(ok?BNET_CMD_OK:BNET_CMD_FAILED);
          found = true;
          break;
       }
       ua->error_msg(_("%s: is an invalid command.\n"), ua->argk[0]);
       ok = false;
    }
-   if (ua->api) user->signal(ok?BNET_CMD_OK:BNET_CMD_FAILED);
    return ok;
 }
 
 
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2002-2008 Free Software Foundation Europe e.V.
+   Copyright (C) 2002-2009 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
          ua->gui = true;
          if (ua->api) user->signal(BNET_CMD_BEGIN);
          ok = (*commands[i].func)(ua, ua->cmd);   /* go execute command */
+         if (ua->api) user->signal(ok?BNET_CMD_OK:BNET_CMD_FAILED);
          ua->gui = gui;
          found = true;
          break;
       ua->error_msg("%s", user->msg);
       ok = false;
    }
-   if (ua->api) user->signal(ok?BNET_CMD_OK:BNET_CMD_FAILED);
    return ok;
 }
 
 
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2007-2008 Free Software Foundation Europe e.V.
+   Copyright (C) 2007-2009 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    m_at_prompt = false;
    m_at_main_prompt = false;
    m_conn = conn;
+   m_in_command = 0;
 }
 
 DirComm::~DirComm()
          if (mainWin->m_commDebug) Pmsg0(000, "CMD OK\n");
          m_at_prompt = false;
          m_at_main_prompt = false;
+//       Pmsg1(000, "before dec m_in_command=%d\n", m_in_command);
+         if (--m_in_command < 0) {
+//          Pmsg0(000, "m_in_command < 0\n");
+            m_in_command = 0;
+         }
          mainWin->set_status(_("Command completed ..."));
          continue;
       case BNET_CMD_BEGIN:
          if (mainWin->m_commDebug) Pmsg0(000, "CMD BEGIN\n");
          m_at_prompt = false;
          m_at_main_prompt = false;
+         m_in_command++;
+//       Pmsg1(000, "after inc m_in_command=%d\n", m_in_command);
          mainWin->set_status(_("Processing command ..."));
          continue;
       case BNET_MAIN_PROMPT:
          break;
       case BNET_CMD_FAILED:
          if (mainWin->m_commDebug) Pmsg0(000, "CMD FAILED\n");
+         if (--m_in_command < 0) {
+            Pmsg0(000, "m_in_command < 0\n");
+         }
          mainWin->set_status(_("Command failed."));
          QApplication::restoreOverrideCursor();
          break;
 
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2007-2008 Free Software Foundation Europe e.V.
+   Copyright (C) 2007-2009 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    char *msg();
    bool notify(bool enable); // enables/disables socket notification - returns the previous state
    bool is_notify_enabled() const;
+   bool is_in_command() const { return m_in_command > 0; };
    void terminate();
    bool connect_dir();                     
    int read(void);
    BSOCK *m_sock;   
    bool m_at_prompt;
    bool m_at_main_prompt;
+   int  m_in_command;
    QSocketNotifier *m_notifier;
    bool m_api_set;
    int m_conn;
 
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2007-2008 Free Software Foundation Europe e.V.
+   Copyright (C) 2007-2009 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
       Pmsg2(000, "dir_cmd conn %i %s\n", conn, cmd);
    notify(conn, false);
    dircomm->write(cmd);
-   while ((stat = dircomm->read()) > 0) {
+   while ((stat = dircomm->read()) > 0 && dircomm->is_in_command()) {
       if (mainWin->m_displayAll) display_text(dircomm->msg());
       strip_trailing_junk(dircomm->msg());
       results << dircomm->msg();
    }
+   if (stat > 0 && mainWin->m_displayAll) display_text(dircomm->msg());
    notify(conn, true);
    discardToPrompt(conn);
    return true;              /* ***FIXME*** return any command error */
 
 
 
 General:
+21Mar09
+Kes  Attempt to correct timing problems with starting bat and obtaining
+     lists. Maintain in_command counter to know when a list is coming.
 20Mar09
 kes  Convert seconds.seq separator into seconds_seq so that Bacula
      editing of the Job name from the full Job name works. This fixes