"node --eval" messes up stdout #572

d0b3 opened this Issue Jan 22, 2011 · 6 comments


None yet

4 participants

d0b3 commented Jan 22, 2011

When using --eval node prints stuff on the console. This is unfortunate because you can't use stdout as a proper data stream any more, when you spawn child processes with --eval. I removed line 671 in src/node.js and it now works like a charm.

668   if (process._eval) {
669     // -e, --eval
670     var rv = new Module()._compile('return eval(process._eval)', 'eval')
671     //console.log(rv);
672     return;
673   }
tj commented Jan 22, 2011

yeah I agree. IMO it should eval and continue doing what it would otherwise (loading the module, etc)

d0b3 commented Jan 24, 2011

There's been a rewrite to src/node.js, the issue is still present thou. Removing line 337 solves the problem.

328   startup.runEval = function() {
329     // -e, --eval
330     if (!process._eval) {
331       return;
332     }
334     var Module = NativeModule.require('module');
336     var rv = new Module()._compile('return eval(process._eval)', 'eval');
337     console.log(rv);
338     return true;
339   };

I like you're idea, having an eval block before loading further javascript from files could come in handy some time.

tj commented Jan 25, 2011

yeah, and you can always --eval console.log(whatever) if you need to, most executables just do a literal eval AFAIK

d0b3 commented Apr 30, 2011

found a simple workaround that works for me
node --eval "console.log=console.error;…"

console.log then passes the arguments to stderr instead of stdout including the mean console.log in src/node.js

@bnoordhuis bnoordhuis added a commit to bnoordhuis/node that referenced this issue Jul 25, 2011
@bnoordhuis bnoordhuis cli: don't print result of --eval unless -p or --print is given
Fixes #572.

@ry - can you review 00a505d?

ry commented Jul 25, 2011

fine - we can remove the console.log - but let's not add this extra --print option... it's making things too complicated

@bnoordhuis bnoordhuis added a commit that closed this issue Jul 25, 2011
@bnoordhuis bnoordhuis cli: don't print result of --eval
Fixes #572.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment