Skip to content

Instantly share code, notes, and snippets.

@wolframkriesing
Created December 31, 2011 15:03
Show Gist options
  • Save wolframkriesing/1544236 to your computer and use it in GitHub Desktop.
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
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
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