MCPcopy
hub / github.com/Unitech/pm2 / exec

Function exec

lib/ProcessContainer.js:112–304  ·  view source on GitHub ↗

* Description * @method exec * @param {} script * @param {} stds * @return

(script, stds)

Source from the content-addressed store, hash-verified

110 * @return
111 */
112function exec(script, stds) {
113 if (p.extname(script) == '.ts' || p.extname(script) == '.tsx') {
114 try {
115 require('ts-node/register');
116 } catch (e) {
117 console.error('Failed to load Typescript interpreter:', e.message || e);
118 }
119 }
120
121 process.on('message', function (msg) {
122 if (msg.type === 'log:reload') {
123 for (var k in stds){
124 if (typeof stds[k] == 'object' && !isNaN(stds[k].fd)){
125 if (stds[k].destroy) stds[k].destroy();
126 else if (stds[k].end) stds[k].end();
127 else if (stds[k].close) stds[k].close();
128 stds[k] = stds[k]._file;
129 }
130 }
131 Utility.startLogging(stds, function (err) {
132 if (err)
133 return console.error('Failed to reload logs:', err.stack);
134 console.log('Reloading log...');
135 });
136 }
137 });
138
139 var dayjs = null;
140
141 if (pm2_env.log_date_format)
142 dayjs = require('dayjs');
143
144 Utility.startLogging(stds, function (err) {
145 if (err) {
146 process.send({
147 type : 'process:exception',
148 data : {
149 message: err.message,
150 syscall: 'ProcessContainer.startLogging'
151 }
152 });
153 throw err;
154 return;
155 }
156
157 process.stderr.write = (function(write) {
158 return function(string, encoding, cb) {
159 var log_data = null;
160
161 // Disable logs if specified
162 if (pm2_env.disable_logs === true) {
163 return cb ? cb() : false;
164 }
165
166 if (pm2_env.log_type && pm2_env.log_type === 'json') {
167 log_data = JSON.stringify({
168 message : string.toString(),
169 timestamp : pm2_env.log_date_format && dayjs ?

Callers 1

Calls 10

cbFunction · 0.85
toStringMethod · 0.80
chdirMethod · 0.80
onMethod · 0.65
destroyMethod · 0.65
endMethod · 0.65
closeMethod · 0.65
sendMethod · 0.65
writeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…