Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

"node --eval" messes up stdout #572

Closed
d0b3 opened this issue Jan 22, 2011 · 6 comments
Closed

"node --eval" messes up stdout #572

d0b3 opened this issue Jan 22, 2011 · 6 comments

Comments

@d0b3
Copy link

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.

[srv/node.js]
667 
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
Copy link

tj commented Jan 22, 2011

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

@d0b3
Copy link
Author

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     }
333 
334     var Module = NativeModule.require('module');
335 
336     var rv = new Module()._compile('return eval(process._eval)', 'eval');
337     console.log(rv);
338     return true;
339   };

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

@tj
Copy link

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
Copy link
Author

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 added a commit to bnoordhuis/node that referenced this issue Jul 25, 2011
@bnoordhuis
Copy link
Member

@ry - can you review 00a505d?

@ry
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants