node.jsnodejitsu

Nodejs nexpect: Get all output lines


I have a simple case where I want to use nexpect to list all files in a folder, and add some expect() functionality later.

nexpect.spawn("ls -la /etc")
        .run(function (err, output, exit) {
            res.send(output);
        });

As a result, I just get one line:

lrwxr-xr-x@ 1 root wheel 11 Oct 2 21:42 /etc -> private/etc

My expectation would be to get all of /etc, since output is defined as "output {Array} Array of lines of output examined" (https://github.com/nodejitsu/nexpect).

As a side question: Is nexpect recommendable as of today (since it hasn't been updated in a year)?


Solution

  • It's because you are on a Mac, and /etc is a symlink. Try adding a /:

    nexpect.spawn("ls -la /etc/") .run(function (err, output, exit) { res.send(output); });