mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
修复任务执行前命令字符转义
This commit is contained in:
parent
8218d4ba94
commit
73601ca853
|
@ -37,9 +37,12 @@ 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) {
|
||||||
const escapeTaskBefore = task_before.replace(/"/g, '\\"');
|
const escapeTaskBefore = task_before
|
||||||
command = `${command} && echo -e '执行前置命令\n' && eval '${escapeTaskBefore}' && echo -e '\n执行前置命令结束\n'`;
|
.replace(/"/g, '\\"')
|
||||||
|
.replace(/\$/g, '\\$');
|
||||||
|
command = `${command} && eval '${escapeTaskBefore}'`;
|
||||||
}
|
}
|
||||||
|
console.log('执行前置命令\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)'"`,
|
||||||
{
|
{
|
||||||
|
@ -52,6 +55,7 @@ function run() {
|
||||||
process.env[key] = newEnvObject[key];
|
process.env[key] = newEnvObject[key];
|
||||||
}
|
}
|
||||||
console.log(output);
|
console.log(output);
|
||||||
|
console.log('执行前置命令结束\n');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (!error.message.includes('spawnSync /bin/sh E2BIG')) {
|
if (!error.message.includes('spawnSync /bin/sh E2BIG')) {
|
||||||
console.log(`run task before error: `, error);
|
console.log(`run task before error: `, error);
|
||||||
|
|
|
@ -44,12 +44,13 @@ def run():
|
||||||
task_before = os.getenv("task_before")
|
task_before = os.getenv("task_before")
|
||||||
|
|
||||||
if task_before:
|
if task_before:
|
||||||
escape_task_before = task_before.replace('"', '\\"')
|
escape_task_before = task_before.replace('"', '\\"').replace("$", "\\$")
|
||||||
command += f" && echo -e '执行前置命令\n' && eval '{escape_task_before}' && echo -e '\n执行前置命令结束\n'"
|
command += f" && eval '{escape_task_before}'"
|
||||||
|
|
||||||
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}\""
|
||||||
|
|
||||||
|
print("执行前置命令\n")
|
||||||
res = subprocess.check_output(command, shell=True, encoding="utf-8")
|
res = subprocess.check_output(command, shell=True, encoding="utf-8")
|
||||||
output, env_str = res.split(split_str)
|
output, env_str = res.split(split_str)
|
||||||
|
|
||||||
|
@ -59,6 +60,7 @@ def run():
|
||||||
os.environ[key] = value
|
os.environ[key] = value
|
||||||
|
|
||||||
print(output)
|
print(output)
|
||||||
|
print("执行前置命令结束")
|
||||||
|
|
||||||
except subprocess.CalledProcessError as error:
|
except subprocess.CalledProcessError as error:
|
||||||
print(f"run task before error: {error}")
|
print(f"run task before error: {error}")
|
||||||
|
@ -82,7 +84,7 @@ def run():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
run()
|
run()
|
||||||
|
|
||||||
from notify import send
|
from notify import send
|
||||||
|
|
||||||
class BaseApi:
|
class BaseApi:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user