MCPcopy
hub / github.com/bower/bower / executeCmd

Function executeCmd

lib/util/cmd.js:57–123  ·  view source on GitHub ↗
(command, args, options)

Source from the content-addressed store, hash-verified

55// Returns a promise that gets fulfilled if the command succeeds
56// or rejected if it fails
57function executeCmd(command, args, options) {
58 var process;
59 var stderr = '';
60 var stdout = '';
61 var deferred = Q.defer();
62
63 // Windows workaround for .bat and .cmd files, see #626
64 if (isWin) {
65 command = getWindowsCommand(command);
66 }
67
68 // Buffer output, reporting progress
69 process = cp.spawn(command, args, options);
70 process.stdout.on('data', function(data) {
71 data = data.toString();
72 deferred.notify(data);
73 stdout += data;
74 });
75 process.stderr.on('data', function(data) {
76 data = data.toString();
77 deferred.notify(data);
78 stderr += data;
79 });
80
81 // If there is an error spawning the command, reject the promise
82 process.on('error', function(error) {
83 return deferred.reject(error);
84 });
85
86 // Listen to the close event instead of exit
87 // They are similar but close ensures that streams are flushed
88 process.on('close', function(code) {
89 var fullCommand;
90 var error;
91
92 if (code) {
93 // Generate the full command to be presented in the error message
94 if (!Array.isArray(args)) {
95 args = [];
96 }
97
98 fullCommand = command;
99 fullCommand += args.length ? ' ' + args.join(' ') : '';
100
101 // Build the error instance
102 error = createError(
103 'Failed to execute "' +
104 fullCommand +
105 '", exit code of #' +
106 code +
107 '\n' +
108 stderr,
109 'ECMDERR',
110 {
111 details: stderr,
112 exitCode: code
113 }
114 );

Callers

nothing calls this directly

Calls 2

getWindowsCommandFunction · 0.85
createErrorFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…