修复任务执行前命令字符转义

This commit is contained in:
whyour
2024-08-19 22:27:09 +08:00
parent 8218d4ba94
commit 73601ca853
2 changed files with 11 additions and 5 deletions
+6 -2
View File
@@ -37,9 +37,12 @@ function run() {
const fileName = process.argv[1].replace(`${dir_scripts}/`, '');
let command = `bash -c "source ${file_task_before} ${fileName}`;
if (task_before) {
const escapeTaskBefore = task_before.replace(/"/g, '\\"');
command = `${command} && echo -e '执行前置命令\n' && eval '${escapeTaskBefore}' && echo -e '\n执行前置命令结束\n'`;
const escapeTaskBefore = task_before
.replace(/"/g, '\\"')
.replace(/\$/g, '\\$');
command = `${command} && eval '${escapeTaskBefore}'`;
}
console.log('执行前置命令\n');
const res = execSync(
`${command} && echo -e '${splitStr}' && NODE_OPTIONS= node -p 'JSON.stringify(process.env)'"`,
{
@@ -52,6 +55,7 @@ function run() {
process.env[key] = newEnvObject[key];
}
console.log(output);
console.log('执行前置命令结束\n');
} catch (error) {
if (!error.message.includes('spawnSync /bin/sh E2BIG')) {
console.log(`run task before error: `, error);