title: Inno Setup - Wait for Postgres database to start
body: <p>In the example below I want to delay the execution of the <code>createuser</code> command until the Postgres server is up and running. </p>
  
  <pre class="lang-pascal prettyprint-override"><code>if Exec('pg_ctl', 'start -D C:\ProgramData\PostgresQL\data', '', SW_SHOW, ewWaitUntilIdle, ResultCode) then
  begin
     Sleep(10000);
     // Create our database  user
     if Exec('createuser', '-w -d -R -S testdb', '', SW_SHOW, ewWaitUntilTerminated, ResultCode)
  </code></pre>
  
  <p>Unfortunately using an arbitrary <code>Sleep()</code> is the only way I've managed to achieve this. The <code>exWaitUntilIdle</code> flag unsurprisingly doesn't do the trick and delay the execution long enough (if at all).</p>
  
  <p>So does anyone have a more robust way of ensuring the <code>createuser</code> is not executed until the Postgres (<code>pg_ctl start</code>) server command is running, idle and ready to accept commands?</p>