Derik Whittaker



Launching External applications w/ Grunt.js

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.  Fortunate 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,

Posted 11-29-2013 6:24 AM by Derik Whittaker
Filed under: ,


About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)