💾 Archived View for gmi.noulin.net › gitRepositories › git-off › file › src › node_modules › sync-ex… captured on 2023-01-29 at 13:14:45. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
README.md (1537B)
1 sync-exec 2 ========= 3 4 An fs.execSync replacement until you get it natively from node 0.12+ 5 6 Upgrading to 0.12.x is usually safe. At that point it will use child_process.execSync. 7 8 You can still force the emulated version passing `{forceEmulated: true}` to the `options` argument. 9 10 11 # Advantages 12 Inspired by [exec-sync](https://www.npmjs.org/package/exec-sync) but comes with a few advantages: 13 - no libc requirement (no node-gyp compilation) 14 - no external dependencies 15 - returns the exit status code 16 - you can pass [execSync options](http://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options) 17 - multiple commands should work pretty safely 18 19 # Installation 20 [sudo] npm install sync-exec 21 22 # Signature 23 exec(cmd[, timeout][, options]); 24 25 # Examples 26 var exec = require('sync-exec'); 27 28 // { stdout: '1\n', 29 // stderr: '', 30 // status: 0 } 31 console.log(exec('echo 1')); 32 33 // You can even pass options, just like for [child_process.exec](http://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback) 34 console.log(exec('ls -la', {cwd: '/etc'})); 35 36 // Times out after 1 second, throws an error 37 exec('sleep 3; echo 1', 1000); 38 39 # How it works (if you care) 40 Your commands STDOUT and STDERR outputs will be channeled to files, also the exit code will be saved. Synchronous file readers will start listening to these files right after. Once outputting is done, values get picked up, tmp files get deleted and values are returned to your code.