child_process#exec JavaScript Examples
The following examples show how to use
child_process#exec.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: commands.js From Docketeer with MIT License | 6 votes |
refreshImages = (callback) => {
exec('docker images', (error, stdout, stderr) => {
if (error) {
alert(`${error.message}`);
return;
}
if (stderr) {
console.log(`refreshImages stderr: ${stderr}`);
return;
}
const value = parseContainerFormat.convert(stdout);
const objArray = ['reps', 'tag', 'imgid', 'size'];
const resultImages = [];
for (let i = 0; i < value.length; i++) {
const innerArray = [];
if (value[i][0] !== '<none>') {
innerArray.push(value[i][0]);
innerArray.push(value[i][1]);
innerArray.push(value[i][2]);
innerArray.push(value[i][6]);
resultImages.push(innerArray);
}
}
const convertedValue = parseContainerFormat
.convertArrToObj(resultImages, objArray);
callback(convertedValue);
});
}
Example #2
Source File: commands.js From Docketeer with MIT License | 6 votes |
getLogs = (optionsObj, getContainerLogsDispatcher) => {
// build inputCommandString to get logs from command line
let inputCommandString = 'docker logs --timestamps ';
if (optionsObj.since) {
inputCommandString += `--since ${optionsObj.since} `;
}
optionsObj.tail ? inputCommandString += `--tail ${optionsObj.tail} ` : inputCommandString += '--tail 50 ';
inputCommandString += `${optionsObj.containerId}`;
const containerLogs = { stdout: [], stderr: [] };
exec(inputCommandString, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
containerLogs.stdout = makeArrayOfObjects(stdout);
containerLogs.stderr = makeArrayOfObjects(stderr);
});
return containerLogs;
}
Example #3
Source File: commands.js From Docketeer with MIT License | 6 votes |
getVolumeContainers = (volumeName, getVolumeContainersList) => {
exec(`docker ps -a --filter volume=${volumeName} --format "{{json .}},"`,
(error, stdout, stderr) => {
if (error) {
console.log(`getVolumeContainers error: ${error.message}`);
return;
}
if (stderr) {
console.log(`getVolumeContainers stderr: ${stderr}`);
return;
}
const dockerOutput = JSON.parse(
`[${stdout
.trim()
.slice(0, -1)
}]`
);
return getVolumeContainersList(listOfVolumeProperties(volumeName, dockerOutput));
});
}
Example #4
Source File: commands.js From Docketeer with MIT License | 6 votes |
getAllDockerVolumes = (getVolumeList) => {
exec('docker volume ls --format "{{json .}},"', (error, stdout, stderr) => {
if (error) {
console.log(`getAllDockerVolumes error: ${error.message}`);
return;
}
if (stderr) {
console.log(`getAllDockerVolumes stderr: ${stderr}`);
return;
}
const dockerOutput = JSON.parse(
`[${stdout
.trim()
.slice(0, -1)
.replaceAll(' ', '')}]`
);
return getVolumeList(filterOneProperty(dockerOutput, 'Name'));
});
}
Example #5
Source File: commands.js From Docketeer with MIT License | 6 votes |
dockerComposeDown = (fileLocation, ymlFileName) => {
return new Promise((resolve, reject) => {
const nativeYmlFilenames = ['docker-compose.yml', 'docker-compose.yaml', 'compose.yml', 'compose.yaml'];
let cmd = `cd ${fileLocation} && docker-compose down`;
// if ymlFilename is not a native yml/yaml file name, add -f flag and non-native filename
if (!nativeYmlFilenames.includes(ymlFileName)) {
cmd = `cd ${fileLocation} && docker-compose -f ${ymlFileName} down`;
}
exec(cmd, (error, stdout, stderr) => {
if (error) {
console.warn(error.message);
return;
}
if (stderr) {
console.log(stderr);
resolve(stderr);
}
if (stdout) {
console.log(stdout);
}
});
});
}
Example #6
Source File: commands.js From Docketeer with MIT License | 6 votes |
dockerComposeUp = (fileLocation, ymlFileName) => {
return new Promise((resolve, reject) => {
const nativeYmlFilenames = ['docker-compose.yml', 'docker-compose.yaml', 'compose.yml', 'compose.yaml'];
let cmd = `cd ${fileLocation} && docker-compose up -d`;
// if ymlFilename is not a native yml/yaml file name, add -f flag and non-native filename
if (!nativeYmlFilenames.includes(ymlFileName)) {
cmd = `cd ${fileLocation} && docker-compose -f ${ymlFileName} up -d`;
}
exec(cmd, (error, stdout, stderr) => {
if (error) {
console.warn(error.message);
return;
}
if (stderr) {
resolve(stderr);
}
if (stdout) {
console.log(stdout);
}
});
});
}
Example #7
Source File: commands.js From Docketeer with MIT License | 6 votes |
inspectDockerContainer = (containerId) => {
exec(`docker inspect ${containerId}`, (error, stdout, stderr) => {
if (error) {
console.log(`inspectDockerContainer error: ${error.message}`);
return;
}
if (stderr) {
console.log(`inspectDockerContainer stderr: ${stderr}`);
return;
}
console.log(stdout);
});
}
Example #8
Source File: commands.js From Docketeer with MIT License | 6 votes |
networkContainers = (getNetworkContainers) => {
exec('docker network ls --format "{{json .}},"', (error, stdout, stderr) => {
if (error) {
console.log(`networkContainers error: ${error.message}`);
return;
}
if (stderr) {
console.log(`networkContainers stderr: ${stderr}`);
return;
}
const dockerOutput = `[${stdout.trim().slice(0, -1).replaceAll(' ', '')}]`;
// remove docker network defaults named: bridge, host, and none
const networkContainers = JSON.parse(dockerOutput).filter(
({ Name }) => Name !== 'bridge' && Name !== 'host' && Name !== 'none'
);
getNetworkContainers(networkContainers);
});
}
Example #9
Source File: commands.js From Docketeer with MIT License | 6 votes |
pullImage = (repo) => {
exec(`docker pull ${repo}`, (error, stdout, stderr) => {
if (error) {
alert(`${error.message}`);
return;
}
if (stderr) {
console.log(`pullImage stderr: ${stderr}`);
return;
}
});
}
Example #10
Source File: commands.js From Docketeer with MIT License | 6 votes |
handlePruneClick = (e) => {
e.preventDefault();
exec('docker system prune --force', (error, stdout, stderr) => {
if (error) {
alert(`${error.message}`);
return;
}
if (stderr) {
console.log(`handlePruneClick stderr: ${stderr}`);
return;
}
});
}
Example #11
Source File: commands.js From Docketeer with MIT License | 6 votes |
removeIm = (id, imagesList, callback_1, callback_2) => {
exec(`docker rmi -f ${id}`, (error, stdout, stderr) => {
if (error) {
alert(
`${error.message}` +
'\nPlease stop running container first then remove.'
);
return;
}
if (stderr) {
console.log(`removeIm stderr: ${stderr}`);
return;
}
callback_1(callback_2);
});
}
Example #12
Source File: commands.js From Docketeer with MIT License | 6 votes |
runIm = (id, runningList, callback_1, callback_2) => {
// props.runIm(ele['imgid'], props.runningList, helper.addRunning, props.addRunningContainers)
exec(`docker run ${id}`, (error, stdout, stderr) => {
if (error) {
alert(`${error.message}`);
return;
}
if (stderr) {
console.log(`runIm stderr: ${stderr}`);
return;
}
});
callback_1(runningList, callback_2);
}
Example #13
Source File: commands.js From Docketeer with MIT License | 6 votes |
runStopped = (
id,
runStoppedContainerDispatcher,
refreshRunningContainers
) => {
exec(`docker start ${id}`, (error, stdout, stderr) => {
if (error) {
alert(`${error.message}`);
return;
}
if (stderr) {
console.log(`runStopped stderr: ${stderr}`);
return;
}
runStoppedContainerDispatcher(id);
});
}
Example #14
Source File: commands.js From Docketeer with MIT License | 6 votes |
stop = (id, callback) => {
exec(`docker stop ${id}`, (error, stdout, stderr) => {
if (error) {
alert(`${error.message}`);
return;
}
if (stderr) {
console.log(`stop stderr: ${stderr}`);
return;
}
callback(id);
});
}
Example #15
Source File: commands.js From Docketeer with MIT License | 6 votes |
remove = (id, callback) => {
exec('docker images', (error, stdout, stderr) => {
if (error) {
alert(`${error.message}`);
return;
}
if (stderr) {
console.log(`remove stderr: ${stderr}`);
return;
}
callback(id);
});
}
Example #16
Source File: commands.js From Docketeer with MIT License | 6 votes |
refreshStopped = (refreshStoppedContainers) => {
exec(
'docker ps -f "status=exited" --format "{{json .}},"',
(error, stdout, stderr) => {
if (error) {
alert(`${error.message}`);
return;
}
if (stderr) {
console.log(`refreshStopped stderr: ${stderr}`);
return;
}
// trim whitespace at end out stdout and slice to remove trailing comma
const dockerOutput = stdout.trim().slice(0, -1);
let output = `[${dockerOutput}]`;
output = JSON.parse(output);
refreshStoppedContainers(output);
}
);
}
Example #17
Source File: commands.js From Docketeer with MIT License | 6 votes |
refreshRunning = (refreshRunningContainers) => {
exec(
'docker stats --no-stream --format "{{json .}},"',
(error, stdout, stderr) => {
if (error) {
alert(`${error.message}`);
return;
}
if (stderr) {
console.log(`refreshRunning stderr: ${stderr}`);
return;
}
const dockerOutput = `[${stdout
.trim()
.slice(0, -1)
.replaceAll(' ', '')}]`;
const convertedValue = JSON.parse(dockerOutput);
refreshRunningContainers(convertedValue);
}
);
}
Example #18
Source File: commands.js From Docketeer with MIT License | 6 votes |
addRunning = (runningList, callback) => {
exec(
'docker stats --no-stream --format "{{json .}},"',
(error, stdout, stderr) => {
if (error) {
alert(`${error.message}`);
return;
}
if (stderr) {
console.log(`addRunning stderr: ${stderr}`);
return;
}
// trim whitespace at end out stdout, slice to remove trailing comma and remove spaces
const dockerOutput = `[${stdout
.trim()
.slice(0, -1)
.replaceAll(' ', '')}]`;
const convertedValue = JSON.parse(dockerOutput);
const newList = [];
for (let i = 0; i < convertedValue.length; i++) {
let isInTheList = false;
for (const container of runningList) {
if (container.cid === convertedValue[i].cid) {
isInTheList = true;
break;
}
}
isInTheList ? '' : newList.push(convertedValue[i]);
}
newList.length ? callback(newList) : '';
}
);
}
Example #19
Source File: AlfwShell.js From ntfstool with MIT License | 6 votes |
/**
* check the {{work}} password
* @returns {Promise}
*/
export function checkSudoPassword(setPwd = false) {
if (setPwd !== false) {
var password = setPwd
} else {
var password = getSudoPwd();
}
return new Promise((resolve, reject) => {
try {
//sudo -Sk Force password
exec(`echo '${password}'|sudo -Sk ls /usr`, (error, stdout, stderr) => {
saveLog.log({
error, stdout, stderr
}, "checkSudoPassword res");
if (checkIncorrectPasswordStr(stderr)) {
console.log("start send SudoPWDEvent >>>>>>>>>>>>>>>>>>>>>>>>>>>>")
ipcRenderer.send("IPCMain",AlConst.SudoPwdEvent);
resolve(false);
} else {
resolve(true);
}
});
} catch (e) {
saveLog.error(e, "checkSudoPassword catch error");
noticeTheSystemError("checkSudoPasswordError");
resolve(true);
}
});
}
Example #20
Source File: AlfwShell.js From ntfstool with MIT License | 6 votes |
/**
* exec the shell code by common user
* @param shell
* @returns {Promise<any>}
*/
export function execShell(shell) {
return new Promise((resolve, reject) => {
try {
exec(shell, (error, stdout, stderr) => {
saveLog.log("execShell", {
code: shell,
stdout: stdout,
stderr: stderr,
})
if (stderr) {
reject(stdout + error);
return;
}
if (!stdout && stderr) {
stdout = stderr;
}
resolve(stdout, stderr)
});
} catch (e) {
saveLog.error(e, "execShell");
}
})
}
Example #21
Source File: node-test-bin.js From ipfs-action with MIT License | 6 votes |
async function execBin (cmd, stdin) {
return new Promise((resolve, reject) => {
const cp = exec(`"${process.execPath}" "${binPath}" ${cmd}`, (err, stdout, stderr) => {
if (err) {
err.stdout = stdout
err.stderr = stderr
return reject(err)
}
resolve({ stdout, stderr })
})
if (stdin != null) {
cp.on('spawn', () => {
cp.stdin.write(stdin)
cp.stdin.end()
})
}
})
}
Example #22
Source File: node-test-bin.js From ipfs-action with MIT License | 6 votes |
async function execBin(cmd, stdin) {
return new Promise((resolve, reject) => {
const cp = exec(`"${ process.execPath }" "${ binPath }" ${ cmd }`, (err, stdout, stderr) => {
if (err) {
err.stdout = stdout;
err.stderr = stderr;
return reject(err);
}
resolve({
stdout,
stderr
});
});
if (stdin != null) {
cp.on('spawn', () => {
cp.stdin.write(stdin);
cp.stdin.end();
});
}
});
}
Example #23
Source File: SeleniumDockerService.js From terra-toolkit-boneyard with Apache License 2.0 | 6 votes |
/**
* Executes an arbitrary command and returns a promise.
* @param {String} command - The command to execute
* @return {Promise}
*/
execute(command) {
return new Promise((resolve, reject) => {
exec(command, (error, stdout) => {
if (error) {
reject(error);
} else {
resolve(stdout);
}
});
});
}
Example #24
Source File: SeleniumDockerService.js From terra-toolkit-boneyard with Apache License 2.0 | 6 votes |
/**
* Gets the stack information.
* @return {Promise} which resolves to a string representing the stack, or null if none exists.
*/
getStack() {
return new Promise((resolve) => {
exec('docker stack ls | grep wdio', (error, stdout) => {
resolve(stdout);
});
});
}
Example #25
Source File: audio-cut.js From HinataMd with GNU General Public License v3.0 | 6 votes |
handler = async (m, { conn, args, usedPrefix, command }) => {
let q = m.quoted ? m.quoted : m
let mime = (q.msg || q).mimetype || ''
if (!/audio/.test(mime)) throw `Balas vn/audio yang ingin diubah dengan caption *${usedPrefix + command}*`
let audio = await q.download?.()
if (!audio) throw 'Can\'t download audio!'
if (!args[0] || !args[1]) throw `example: ${usedPrefix + command} 00:00:30 00:00:30`
let ran = (new Date * 1) + '.mp3'
let media = '../tmp/' + ran
let filename = media + '.mp3'
await promises.writeFile(media, audio)
exec(`ffmpeg -ss ${args[0]} -i ${media} -t ${args[1]} -c copy ${filename}`, async (err) => {
await promises.unlink(media)
if (err) return Promise.reject( `_*Error!*_`)
let buff = await promises.readFile(filename)
m.reply(wait)
conn.sendFile(m.chat, buff, filename, null, m, true, { quoted: m, mimetype: 'audio/mp4' })
await promises.unlink(filename)
})
}
Example #26
Source File: audio-changer.js From HinataMd with GNU General Public License v3.0 | 5 votes |
handler = async (m, { conn, args, usedPrefix, command }) => {
try {
let q = m.quoted ? m.quoted : m
let mime = (q.msg || q).mimetype || ''
if (!/audio/.test(mime)) throw `Balas vn/audio yang ingin diubah dengan caption *${usedPrefix + command}*`
let audio = await q.download?.()
if (!audio) throw 'Can\'t download audio!'
if (!args[0] || !args[1]) throw 'xample: .bass 10 10'
if (isNaN(args[0]) || isNaN(args[1])) return m.reply('Pake angka')
let set
if (/bass/.test(command)) set = `-af equalizer=f=${args[0]}:width_type=o:width=2:g=${args[1]}`
if (/volume/.test(command)) set = `-af volume=${args[0]} -vcodec copy`
if (/blown/.test(command)) set = '-af acrusher=.1:1:64:0:log'
if (/deep/.test(command)) set = '-af atempo=4/4,asetrate=44500*2/3'
if (/earrape/.test(command)) set = '-af volume=12'
if (/fast/.test(command)) set = `-filter:a "atempo=1.63,asetrate=${args[0]}"`
if (/fat/.test(command)) set = `-filter:a "atempo=1.6,asetrate=22100"`
if (/nightcore/.test(command)) set = '-filter:a atempo=1.06,asetrate=44100*1.25'
if (/reverse/.test(command)) set = '-filter_complex "areverse"'
if (/robot/.test(command)) set = '-filter_complex "afftfilt=real=\'hypot(re,im)*sin(0)\':imag=\'hypot(re,im)*cos(0)\':win_size=512:overlap=0.75"'
if (/slow/.test(command)) set = `-filter:a "atempo=1.0,asetrate=${args[0]}"`
if (/smooth/.test(command)) set = '-filter:v "minterpolate=\'mi_mode=mci:mc_mode=aobmc:vsbmc=1:fps=120\'"'
if (/tupai|squirrel|chipmunk/.test(command)) set = '-filter:a "atempo=0.5,asetrate=65100"'
if (/vibra/.test(command)) set = '-filter_complex "vibrato=f=15"'
let ran = (new Date * 1) + '.mp3'
let media = '../tmp/' + ran
let filename = media + '.mp3'
await promises.writeFile(media, audio)
exec(`ffmpeg -i ${media} ${set} ${filename}`, async (err) => {
await promises.unlink(media)
if (err) return Promise.reject( `_*Error!*_`)
let buff = await promises.readFile(filename)
m.reply(wait)
conn.sendFile(m.chat, buff, ran, null, m, /vn/.test(args[0]), { quoted: m, mimetype: 'audio/mp4' })
await promises.unlink(filename)
})
} catch (e) {
throw e
}
}
Example #27
Source File: AlfwShell.js From ntfstool with MIT License | 5 votes |
/**
* exec the shell code by root
* force Ignore result
* @param shell
* @param force
* @returns {Promise}
*/
export function execShellSudo(shell, force = false) {
return new Promise((resolve, reject) => {
var password = getSudoPwd();
try {
exec(`echo '${password}'|sudo -Sk ${shell}`, (error, stdout, stderr) => {
stderr = stderr.replace( /^Password:/gi , '')
saveLog.log("execShellSudo", {
code: "[SUDO]" + shell,
stdout: stdout,
stderr: stderr,
// error:error
})
if (force == true) {
resolve();
return;
}
if (stderr) {
if (checkIncorrectPasswordStr(stderr)) {
checkSudoPassword().then(res => {
if (!res) {
reject(stderr);
return;
}
});
}else if(!checkFuseStr(stderr)){
ipcRenderer.send("IPCMain",AlConst.InstallFuseEvent);
}else if(!checkNotSudoer(stderr)){
console.warn("checkNotSudoer ok");
ipcRenderer.send("IPCMain",{
name:AlConst.NotSudoerEvent,
data:stderr
});
} else {
reject(stderr);
return;
}
} else {
resolve(stdout, stderr)
}
});
} catch (e) {
saveLog.error(e, "execShellSudo");
}
})
}
Example #28
Source File: index.js From watchlist with MIT License | 5 votes |
toExec = promisify(exec)
Example #29
Source File: early-exit.js From action-dependabot-auto-merge with MIT License | 5 votes |
pexec = promisify(exec)