【发布时间】:2020-08-12 19:39:17
【问题描述】:
使用 Node 自动化我的一些 bash 进程。
const { exec } = require("child_process");
let buildCommand = "docker build -t vm1:v1 ./nginx1 "
let runCommand = "docker run -d -p 6001:6001 --name clientvm1 vm1:v1"
//run first command
exec(buildCommand, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
//run second command
exec(runCommand, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
让第二个命令等到第一个命令完成的最佳方法是什么?
【问题讨论】: