DevOps Zone is brought to you in partnership with:

Derik Whittaker is a Software Architect who specializes in all things .Net. Derik has been building enterprise systems on top of the .Net technology stack for over 12 years and along the way has picked up a thing or two about how to create killer systems. During his 12 year career Derik has worked in many different industries ranging from Marking, Healthcare, Retail, Insurance, Automotive and Online Entertainment. Currently Derik is working for a Technology startup (VStrator) in Raleigh North Carolina helping them build out a best of breed technology solution which will enable their users to create world class coaching solutions. Derik believes that the job of a developer is more than just turning syntax into working 1’s and 0’s. Derik is a DZone MVB and is not an employee of DZone and has posted 22 posts at DZone. You can read more from them at their website. View Full User Profile

Launching External Applications with Grunt.js

12.02.2013
| 3782 views |
  • submit to reddit

I am using Grunt.js as my build/task tool for a project I am working on and I needed the ability to launch an external, console application via Grunt.  Fortunately for me there is an existing plugin called grunt-exec which can handle just this need.

When I sat down to add grunt-exec to my gruntfile.js script everything worked during my test runs, but when I went to launch the real console application I quickly realized that something was not right. 

Take a look at my grunt setup below

You can see that all I am doing is calling the cmd executable and passing it the path to my  application to be launched.  The issue is that this code will run the exe in the same space as the console and I wanted my ServerHost.exe to run in its own instance.

To try to resolve this I thought I would simply use the start command (see below), sadly this caused other issues.

When I ran the code above it would correctly launch a 2nd console instance, but it would not start my application, no idea why.  However, I thought it may have been the path to the .exe so I added single quotes around the path to see if that would help…sadly it did not.

I realized that my issue was that I need to change my current working directory to be the same as my .exe, but how to do this because I could only issue one command via the grunt-exec command.  It then dawned on me that I could use the ‘&’ in my commands and have the left command run followed by the right command.

Using the ‘&’ I changed my script be below and everything just worked

The moral of this story is you can use Grunt.Js to launch external applications, it just takes a bit of patience to get the command correct to do so. 

Till next time,

Published at DZone with permission of Derik Whittaker, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)