帮我解释代码: /** * Run command and get stdout * @param shell * @param options */ export function runCommand( shell: string, options: string[], timeout = 10000 ): Promise { return new Promise((resolve, reject) => { let errorTriggered = false; let output = ""; let errorMessage = ""; const process = spawn(shell, options, { timeout }); process.stdout.on("data", (chunk) => { output += ${chunk}
; }); process.stderr.on("data", (chunk) => { errorMessage += ${chunk}
; }); process.on("exit", (code) => { if (process.killed) { console.log("Process took too long and was killed"); } if (!errorTriggered) { if (code === 0) { resolve(output); } else { reject(errorMessage); } } }); process.on("error", (error) => { errorTriggered = true; reject(error); }); }); }
去博客设置页面,选择一款你喜欢的代码片高亮样式,下面展示同样高亮的 代码片
.
// An highlighted block
var foo = 'bar';