Skip to content

Instantly share code, notes, and snippets.

@wolframkriesing
Created December 31, 2011 15:03
Show Gist options
  • Select an option

  • Save wolframkriesing/1544236 to your computer and use it in GitHub Desktop.

Select an option

Save wolframkriesing/1544236 to your computer and use it in GitHub Desktop.
find vs. exec(find)
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
@wolframkriesing

Copy link
Copy Markdown
Author

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 ...

@sebs

sebs commented Jan 1, 2012

Copy link
Copy Markdown

Maybe the stuff gets "streamed" from some certain pont on and comes in chunks? look at the output of your script i'd say ;)

@wolframkriesing

Copy link
Copy Markdown
Author

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!!!

@wolframkriesing

Copy link
Copy Markdown
Author

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