| 213 | //@ **command injection**. For more context, consult the [Security |
| 214 | //@ Guidelines](https://github.com/shelljs/shelljs/wiki/Security-guidelines). |
| 215 | function _exec(command, options, callback) { |
| 216 | options = options || {}; |
| 217 | |
| 218 | var pipe = common.readFromPipe(); |
| 219 | |
| 220 | // Callback is defined instead of options. |
| 221 | if (typeof options === 'function') { |
| 222 | callback = options; |
| 223 | options = { async: true }; |
| 224 | } |
| 225 | |
| 226 | // Callback is defined with options. |
| 227 | if (typeof options === 'object' && typeof callback === 'function') { |
| 228 | options.async = true; |
| 229 | } |
| 230 | |
| 231 | options = common.extend({ |
| 232 | silent: common.config.silent, |
| 233 | fatal: common.config.fatal, |
| 234 | async: false, |
| 235 | }, options); |
| 236 | |
| 237 | if (!command) { |
| 238 | try { |
| 239 | common.error('must specify command'); |
| 240 | } catch (e) { |
| 241 | if (options.fatal) { |
| 242 | throw e; |
| 243 | } |
| 244 | |
| 245 | return; |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | if (options.async) { |
| 250 | return execAsync(command, options, pipe, callback); |
| 251 | } else { |
| 252 | return execSync(command, options, pipe); |
| 253 | } |
| 254 | } |
| 255 | module.exports = _exec; |