title: Start 2 terminals simultaneously. Execute command in first only after the second outputs text X
body: <p>We have the following use case:</p>
  
  <ol>
  <li>Run a command (third party, no control over the source code) that starts a development server with an integrated "file watcher" that recompiles the source files and restarts the server when it detects file changes (and publishes the output to a /dist folder only in the very last seconds of the ~30 second process; the /dist folder is created as a last step of the publishing process).</li>
  <li>Run a secondary "post-processing" command that should only execute when the previous command has successfully started the server and published the files to the /dist folder (this command publishes some additional static files to the /dist folder, so it's dependant on the existence of the folder).</li>
  </ol>
  
  <p>There are several issues with this approach:</p>
  
  <ul>
  <li>The command from step 1 "steals" the terminal, meaning that it never terminates (due to the file watcher). So executing the two commands in sequence is not an option.</li>
  <li>The second command should wait for Terminal 1 to output a certain string (e.g. "Server Started"), which means the /dist folder is now ready. Only then it should come in effect.</li>
  </ul>
  
  <p>As of this moment we have put a reasonable "sleep" in the beginning of the second terminal, just so it waits for the first command to do the publishing and the /dist folder exists. The issue is that on slower computers this sleep period is not enough (the second command starts executing before the first one had enough time to create the /dist folder). On fast computers, the first command finishes rather quickly and there is a rather awkward waiting time before the second command starts. For development purposes, this is very annoying.</p>
  
  <p>Is there a way to automate this two step process?</p>
  
  <p>To rephrase:</p>
  
  <p>Is there a way to make a terminal X, start a secondary Terminal Y and wait for Terminal Y to output a certain string before doing some action. And preferrably doing this same action when Terminal Y outputs the said string over and over.</p>
  
  <p>We prefer a Windows solution if possible, but Linux is also an option if no solution is found.</p>