expressjs view variables

I'm struggling to figure this one out and I'm sure it's not this complicated. For some reasonI get the error below from this code:

/*
 * GET home page.
 */

exports.index = function(req, res){
    exec('ls -l ~/Sites/branches | grep "^d"', function (error, stdout, stderr) {
        // var lines = stdout.split("\n");
        // var folder;
        // lines.forEach(function(line){
        //     folder = line.match(/([^\s]+)$/igm);
        //     if (folder!='null') {
        //         sys.puts(folder);
        //     }
        // });
        res.render('index', {
            title: 'Express',
            lines: 'hi'
        });
    });

};

I've commented out the lines where I intend to get the data for lines from and simply set lines to a string. It gives me the error below regardless.

Express
500 ReferenceError: /Users/luisgomez/Desktop/mashlocaldevman/views/index.ejs:10 8| <h1><%= title %></h1> 9| <p>Welcome to <%= title %></p> >> 10| <p>Lines: <%= lines.length %></p> 11| </body> 12| </html> 13| lines is not defined
<%= title %>
Welcome to <%= title %>

Lines: <%= lines.length %>

lines is not defined
at eval (eval at (/Users/luisgomez/Desktop/mashlocaldevman/node_modules/ejs/lib/ejs.js:226:12))
at exports.compile (/Users/luisgomez/Desktop/mashlocaldevman/node_modules/ejs/lib/ejs.js:228:15)
at Object.exports.render (/Users/luisgomez/Desktop/mashlocaldevman/node_modules/ejs/lib/ejs.js:266:13)
at View.exports.renderFile [as engine] (/Users/luisgomez/Desktop/mashlocaldevman/node_modules/ejs/lib/ejs.js:292:22)
at View.render (/Users/luisgomez/Desktop/mashlocaldevman/node_modules/express/lib/view.js:75:8)
at Function.app.render (/Users/luisgomez/Desktop/mashlocaldevman/node_modules/express/lib/application.js:504:10)
at ServerResponse.res.render (/Users/luisgomez/Desktop/mashlocaldevman/node_modules/express/lib/response.js:677:7)
at exports.index (/Users/luisgomez/Desktop/mashlocaldevman/routes/index.js:7:7)
at callbacks (/Users/luisgomez/Desktop/mashlocaldevman/node_modules/express/lib/router/index.js:165:11)
at param (/Users/luisgomez/Desktop/mashlocaldevman/node_modules/express/lib/router/index.js:139:11)

I'm using simple HTML for the views and the latest version of express. The view renders fine if I remove the 'lines variable from the render call.

Any ideas?

Thank you,

Luis

If you comment out lines, then lines will not be defined so length cannot be evaluated:

Lines: <%= lines.length %>

If you uncomment that code but for some reason stdout is empty (is stderr populated?) then lines could not be defined as well.

Have you tried checking whether error or stderr !== null and logging it out?

Something like:

function (error, stdout, stderr) {
    console.log('stdout: ' + stdout);
    console.log('stderr: ' + stderr);
    if (error !== null) {
      console.log('exec error: ' + error);
    }
}