修复任务中 task_before 参数双引号解析

This commit is contained in:
whyour 2024-07-26 11:30:03 +08:00
parent 0da8155bac
commit be2da98674
2 changed files with 4 additions and 2 deletions

View File

@ -45,7 +45,8 @@ function run() {
const fileName = process.argv[1].replace(`${dir_scripts}/`, ''); const fileName = process.argv[1].replace(`${dir_scripts}/`, '');
let command = `bash -c "source ${file_task_before} ${fileName}`; let command = `bash -c "source ${file_task_before} ${fileName}`;
if (task_before) { if (task_before) {
command = `${command} && echo -e '执行前置命令\n' && eval '${task_before}' && echo -e '\n执行前置命令结束\n'`; const escapeTaskBefore = task_before.replace(/"/g, '\\"');
command = `${command} && echo -e '执行前置命令\n' && eval '${escapeTaskBefore}' && echo -e '\n执行前置命令结束\n'`;
} }
const res = execSync( const res = execSync(
`${command} && echo -e '${splitStr}' && NODE_OPTIONS= node -p 'JSON.stringify(process.env)'"`, `${command} && echo -e '${splitStr}' && NODE_OPTIONS= node -p 'JSON.stringify(process.env)'"`,

View File

@ -55,7 +55,8 @@ def run():
task_before = os.getenv("task_before") task_before = os.getenv("task_before")
if task_before: if task_before:
command += f" && echo -e '执行前置命令\n' && eval '{task_before}' && echo -e '\n执行前置命令结束\n'" escape_task_before = task_before.replace('"', '\\"')
command += f" && echo -e '执行前置命令\n' && eval '{escape_task_before}' && echo -e '\n执行前置命令结束\n'"
python_command = "PYTHONPATH= python3 -c 'import os, json; print(json.dumps(dict(os.environ)))'" python_command = "PYTHONPATH= python3 -c 'import os, json; print(json.dumps(dict(os.environ)))'"
command += f" && echo -e '{split_str}' && {python_command}\"" command += f" && echo -e '{split_str}' && {python_command}\""