Skip to content

Instantly share code, notes, and snippets.

@PavelGavlik
Created November 7, 2012 14:59
Show Gist options
  • Save PavelGavlik/4032087 to your computer and use it in GitHub Desktop.
Save PavelGavlik/4032087 to your computer and use it in GitHub Desktop.
Compile and run program after code change
module.exports = function( grunt ) {
'use strict';
// Compile and run program after code change
//
// Assumptions:
// 1) One cpp file named 1.cpp
// 2) One resulting binary a.out compiled with g++
grunt.initConfig({
// Project configuration
// ---------------------
// watch configuration
watch: {
recompile: {
files: [
'1.cpp'
],
tasks: 'compile run'
}
}
});
grunt.registerTask('compile', 'run compiler', function () {
var done = this.async();
require('child_process').exec('g++ 1.cpp', function (err, stdout, stderr) {
grunt.log.write(stdout + stderr);
done(err);
});
});
grunt.registerTask('run', 'run binary', function () {
var done = this.async();
require('child_process').exec('./a.out', function (err, stdout, stderr) {
grunt.log.write(stdout + stderr);
done(err);
});
});
grunt.registerTask('default', 'watch');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment