0

I want to include my linkchecker test into grunt. I can execute it just fine with powershell

& 'C:\Program Files (x86)\LinkChecker\linkchecker.exe' http://localhost:3000

This is my Gruntfile:

module.exports = function (grunt) {

    //load plugins
    [
        'grunt-cafe-mocha',
        'grunt-contrib-jshint',
        'grunt-exec',
    ].forEach(
        function(task){
            grunt.loadNpmTasks(task);
        }
    );

    //configure plugins
    grunt.initConfig(
        {
/*          cafemocha: {
                all: {
                    src: 'qa/tests-*.js',
                    options: {
                        ui: 'tdd',
                    }
                }
            },*/
            jshint: {
                app: [
                    'meadowlark.js',
                    'public/js/**/*.js',
                    'lib/**/*.js',
                ],
                qa: [
                    'Gruntfile.js',
                    'public/qa/**/*.js',
                    'qa/**/*.js,'
                ]
            },
            exec: {
                linkchecker: {
                    cmd: '\& \'C:\\Program Files (x86)\\LinkChecker\\linkchecker.exe\' http://localhost:3000'
                }
            },
        }
    );

    //register tasks
    grunt.registerTask(
        'default',
        [/*'cafemocha',*/ 'jshint', 'exec']
    );
};

I'm getting a real headache integrating that call to linkchecker into grunt. I have tried several calls for line 39:

1.Escaping everything with full path:

cmd: '& \'C:\\Program Files (x86)\\LinkChecker\\linkchecker.exe\' http://localhost:3000'

Result:

"&" kann syntaktisch an dieser Stelle nicht verarbeitet werden. Exited with code: 1.

Translation: Can't handle the &

2.Escaping everything and the &with full path:

cmd: '\& \'C:\\Program Files (x86)\\LinkChecker\\linkchecker.exe\' http://localhost:3000'

Result:

^ [W044] Bad or unnecessary escaping.

3.Setting up a local variable for the path to linkchecker.exe:

cmd: '$env:linkchecker http://localhost:3000'

Result:

Die Syntax f�r den Dateinamen, Verzeichnisnamen oder die Datentr�gerbezeichnung ist falsch. Exited with code: 1.

Translation: The local variable $env:linkchecker didn't get resolved

4.Outsourcing the call to a script.

cmd: '.\\qa\\linkchecker.ps1'

Result: linkchecker.ps1 gets openend in a editor.

I have also tried grunt-shell. The problem seems to be that grunt has to pass on the & to the shell. It can't handle the &, and escaping it with \& doesn't help either.

mles
  • 4,534
  • 10
  • 54
  • 94

3 Answers3

2

Finally figured it out:

cmd: '"C:\\Program Files (x86)\\LinkChecker\\linkchecker.exe" http://localhost:3000'
mles
  • 4,534
  • 10
  • 54
  • 94
1

Have you tried surrounding the string with double quotes (") on the outside and/or using urlencoded & (%26)

theannouncer
  • 1,148
  • 16
  • 28
  • getting the same errors with that as with try #1. `%26` gets translated to `&` and grunt can't handle that. – mles Aug 06 '14 at 12:56
1

Try making the ps1 file a bat file. If you have an exe file not sure why you need PowerShell.

cmd: '.\\qa\\linkchecker.bat'

..since you mentioned that the file gets opened in a text editor.

Also know that you can use ^ char to escape &.

bhantol
  • 9,368
  • 7
  • 44
  • 81
  • That works, thanks for pointing me in the right direction. I just always use the powershell for developing. – mles Aug 14 '14 at 06:31