Over a million developers have joined DZone.

Launching External Applications with Grunt.js

· DevOps Zone

The DevOps zone is brought to you in partnership with Sonatype Nexus. The Nexus suite helps scale your DevOps delivery with continuous component intelligence integrated into development tools, including Eclipse, IntelliJ, Jenkins, Bamboo, SonarQube and more. Schedule a demo today

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,

The DevOps zone is brought to you in partnership with Sonatype Nexus. Use the Nexus Suite to automate your software supply chain and ensure you're using the highest quality open source components at every step of the development lifecycle. Get Nexus today

Topics:

Published at DZone with permission of Derik Whittaker, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}