Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/sites/node_modules/aws-sdk/scripts/lib/ drwxr-xr-x | |
| Viewing file: Select action/file-type: const { exec, spawn } = require('child_process');
/**
* wrap child_process.exec with retry. Will throw immediately when return
* code not 0; Used for trivial commands since error detail won't be printed.
* @param {string} command
* @param {structure} execOptoins
* @param {number} retryCount
*/
async function executeCommand(command, execOptoins = {}, retryCount = 1) {
try {
const execCommand = command.join(' ');
const { stderr, stdout } = await execute(execCommand, execOptoins);
if (stderr) process.stderr.write(stderr.toString());
if (stdout) process.stderr.write(stdout.toString());
} catch (error) {
if (retryCount > 0) {
await executeCommand(command, execOptoins, --retryCount);
} else {
throw error;
}
}
}
function execute(command, options) {
return new Promise((resolve, reject) => {
exec(command, options, (err, stdout, stderr) => {
if (err) {
reject(err);
} else {
resolve({
stdout: stdout,
stderr: stderr
});
}
});
})
}
/**
* wrap child_process.spawn with retry
* @param {string} command
* @param {structure} execOptions
* @param {number} retryCount
*/
async function executeLongProcessCommand(command, execOptions = {}, retryCount = 1) {
try {
const firstCommand = command[0];
const options = command.slice(1);
await promisifiedSpawn(firstCommand, options, execOptions);
} catch (error) {
if (retryCount > 0) {
await executeLongProcessCommand(command, execOptions, --retryCount);
} else {
throw error;
}
}
}
function promisifiedSpawn(command, options, execOptions) {
return new Promise((resolve, reject) => {
const subProcess = spawn(command, options, execOptions);
subProcess.stdout.on('data', (data) => {
process.stdout.write(data.toString());
});
subProcess.stderr.on('data', (data) => {
process.stderr.write(data.toString());
});
subProcess.on('error', (err) => {
console.error('spawn error: ', err);
});
subProcess.on('close', (code) => {
if (code === 0) {
resolve();
} else {
reject(`"${command} ${options.join(' ')}" exited with code: ${code}`);
}
});
});
}
module.exports = {
execute: executeCommand,
executeLongProcess: executeLongProcessCommand,
} |
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0382 ]-- |