Skip to content

Fix issue #63, accepts input via stdin #64

wants to merge 1 commit into from

2 participants


To read files from stdin, give a dash (-) in place of a file path. For example:

cat some_file.js | jshint -

This matches the conventions of established Unix tools like grep.

The implementation in this changeset is platform dependent, since the only way that I know of to read from stdin synchronously is to call fs.readFileSync('/dev/stdin', 'utf-8'). I also put together an async refactor that might allow reading from stdin to work on platforms that do not have a /dev/stdin file (i.e. Windows). But that would be a much bigger change.

@hallettj hallettj Fix issue #63, accepts input via stdin
To read files from stdin, give a dash (-) in place of a file path.  For example:

    cat some_file.js | jshint -

This is great (and tests!). It definitely would be ideal (like you mentioned) to be platform in dependant though... However, couldn't you have just used process.stdin (unless that's what you meant by async refactor)?

@hallettj hallettj added a commit to hallettj/node-jshint that referenced this pull request Dec 16, 2011
@hallettj hallettj WIP #64: refactor to read input asynchronously 587560d

Yeah, as far as I know as a Readable Stream process.stdin has no blocking read method. So I think that if you want to use the standard stdin API, then the only option is to read input asynchronously.

I got the idea of using /dev/stdin from this thread:

The refactor that I worked on is at hallettj@587560d. The code is working - though it could probably be simplified a bit. I got partway through updating the tests to match the new async behavior when I decided to look for a simpler solution.


Ah, thanks for the information (a bit more complicated, indeed). I have no objections to the /dev/stdin way... although it would be super awesome to make this platform independent (right away)... So, If you wouldn't mind finishing and submitting the async implementation, that would be much appreciated. However, If you really want to get this in, I can merge this, do a publish, and create a techdebt Issue to make it work on windows (via process.stdin). :-s

PS Would you mind adding some info about this to the README? If not I can do that.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.