6

It seems that Node.js (version v0.10.13) returns the command wrapped between ( and \n), here's a minimal example:

require('repl').start({
    'eval': function (cmd, context, filename, callback) {
        callback(null, cmd);
    }
});

The behavior is the following:

$ node repl.js
> asd
'(asd\n)'
>

Why is that? If this feature is documented then I was not able to find it.

Also, if this is the intended behavior, is there a better solution than doing cmd = cmd.slice(1, -2);?

2 Answers 2

1

The issue is already fixed (see commit 9ef9a9de from Aug 2013). Now only JSON expression is wrapped into parens.

Sign up to request clarification or add additional context in comments.

1 Comment

Fixed in the unstable version.
0

As a workaround you can capture stdin stream to a variable and use it instead. I think node does it because user input supposed to be a js expression, which is good to be wrapped in closure ().

var buffer = '';

process.stdin.on('data', function(chunk) {
  buffer += chunk.toString('utf8');
});

require('repl').start({
    input: process.stdin,
    output: process.stdout,
    'eval': function (cmd, context, filename, callback) {
      console.log(buffer);
      buffer = '';
      callback(null, true);
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.