Skip to content

Instantly share code, notes, and snippets.

@athap
Last active August 29, 2015 13:57
Show Gist options
  • Save athap/9678318 to your computer and use it in GitHub Desktop.
Save athap/9678318 to your computer and use it in GitHub Desktop.
Watch File And List File Information By Spawning A Process
var fs = require('fs');
var spawnProcess = require('child_process').spawn;
var filename = 'some/file'
fs.watch(filename, function() {
var list = spawnProcess('ls', ['-lh', filename]);
var info = '';
// listener get invoked every time a chunk of data is available. Data is read in chunks
list.stdout.on('data', function(chunk) {
output += chunk.toString();
});
// When child process exit, it emits the close event
list.on('close', function() {
var parts = output.split(/\s+/);
console.dir([parts[0], parts[4], parts[8]]);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment