Created
December 31, 2011 15:03
-
-
Save wolframkriesing/1544236 to your computer and use it in GitHub Desktop.
find vs. exec(find)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
me@localhost:~> find /Applications/ -iname *.plist | wc -l | |
6660 | |
me@localhost:~> node -e "require('child_process').exec('find /Applications/ -iname *.plist', function(_, stdout){ console.log(stdout.split('\n').length) })" | |
1806 | |
// Why does the same find ran on the cmdline return a different number than when used via exec in node? | |
// Found the bug | |
// This works: | |
me@localhost:~> node -e "require('child_process').exec('find /Applications/ -iname *.plist', {maxBuffer:10000*1024}, function(_, stdout){ console.log(stdout.split('\n').length) })" | |
6661 | |
me@localhost:~> find /Applications/ -iname *.plist | wc -l | |
6660 |
good question, actually not. I tried it on a self created directory. It seems that there is no difference for small amounts of files, but when it gets near thousand it starts to differ by one or two, the higher the more ...
Maybe the stuff gets "streamed" from some certain pont on and comes in chunks? look at the output of your script i'd say ;)
good idea, i found the bug:
node -e "require('child_process').exec('find /Applications/ -iname .plist', {maxBuffer:10000_1024}, function(, stdout){ console.log(stdout.split('\n').length) })"
does work properly!!!
the maxBuffer argument determines the buffer size and therefore the result are only reported as they fit in there
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
user rights in node idfferent from find?