title: gulp: exec multiple commands serially
body: <p>I want to use gulp and imagemagick to batch resize images. Because I couldn't find a current gulp wrapper for imagemagick, I decided to just run imagemagick via <code>exec</code> in gulp. Like so:</p>
  
  <pre><code>gulp.task('images-large', function (cb) {
      exec('mogrify -path .\\images\\large -scale "1920x1080^" -gravity north -crop 1920x1080+0+0 .\\raw_images\\*.*', function (err, stdout, stderr) {
          console.log(stdout);
          console.log(stderr);
          cb(err);
      });
  });
  
  gulp.task('images-medium', function (cb) {
      exec('mogrify -path .\\images\\medium -scale "960x450^" -gravity north -crop 960x450+0+0 .\\raw_images\\*.*', function (err, stdout, stderr) {
          console.log(stdout);
          console.log(stderr);
          cb(err);
      });
  });
  </code></pre>
  
  <p>Both of the above taks work fine, <em>when run separately</em>. Images of various sizes go in, come back out uniform. Now comes the problem. If I combine two similar tasks:</p>
  
  <pre><code>gulp.task('image', [
      'image-large',
      'image-medium'
  ]);
  </code></pre>
  
  <p>Then both large and medium images come out with random sizes. I'm guessing imagemagick doesn't like running multiple <code>mogrify</code> commands simultaneously. Maybe because it actually modifies the original image temporarily? It is a mystery to me. </p>
  
  <p>Rather than fight with imagemagick (generally a losing proposition), I would prefer to just run my image transforms serially, large, then medium. Is there a way to run serial <code>exec()</code> commands in gulp? That is, wait for one exec to complete before running the next?  </p>
  
  <p>I tried something like this:</p>
  
  <pre><code>gulp.task('images-medium', ['images-large'], function (cb) {...});
  </code></pre>
  
  <p>Sadly, images remained randomly sized.</p>
  
  <p>Plan B is to move the imagemagick stuff over to a node script and then run the node script from gulp, but that's verging into Rube Goldberg territory and I'm not sure it's my best option.</p>
  
  <p>Less likely, is there something I can do to make imagemagick behave?</p>