diff --git a/shell/otask.sh b/shell/otask.sh index b1397c67..0c15326b 100755 --- a/shell/otask.sh +++ b/shell/otask.sh @@ -216,8 +216,13 @@ check_file() { if [[ -f $file_env ]]; then get_env_array if [[ $isJsOrPythonFile == 'true' ]]; then - export NODE_OPTIONS="${NODE_OPTIONS} -r ${file_preload_js}" - export PYTHONPATH="${PYTHONPATH}:${dir_preload}:${dir_config}" + PREV_NODE_OPTIONS="${NODE_OPTIONS}" + PREV_PYTHONPATH="${PYTHONPATH}" + if [[ $1 == *.js ]] || [[ $1 == *.ts ]]; then + export NODE_OPTIONS="${NODE_OPTIONS} -r ${file_preload_js}" + else + export PYTHONPATH="${PYTHONPATH}:${dir_preload}:${dir_config}" + fi else . $file_env fi @@ -265,6 +270,10 @@ if [[ $isJsOrPythonFile == 'false' ]]; then run_task_before "${task_shell_params[@]}" fi main "${task_shell_params[@]}" +if [[ $isJsOrPythonFile == 'true' ]]; then + export NODE_OPTIONS="${PREV_NODE_OPTIONS}" + export PYTHONPATH="${PREV_PYTHONPATH}" +fi run_task_after "${task_shell_params[@]}" clear_env handle_task_end "${task_shell_params[@]}" diff --git a/shell/preload/sitecustomize.js b/shell/preload/sitecustomize.js index 5b670e44..e7cea2ad 100644 --- a/shell/preload/sitecustomize.js +++ b/shell/preload/sitecustomize.js @@ -41,10 +41,10 @@ function run() { const fileName = process.argv[1].replace(`${dir_scripts}/`, ''); let command = `bash -c "source ${file_task_before} ${fileName}`; if (task_before) { - command = `${command} && echo -e '执行前置命令\n' && eval "${task_before}" && echo -e '\n执行前置命令结束\n'`; + command = `${command} && echo -e '执行前置命令\n' && eval '${task_before}' && echo -e '\n执行前置命令结束\n'`; } const res = execSync( - `${command} && echo "${splitStr}" && NODE_OPTIONS= node -p 'JSON.stringify(process.env)'"`, + `${command} && echo -e '${splitStr}' && NODE_OPTIONS= node -p 'JSON.stringify(process.env)'"`, { encoding: 'utf-8', }, diff --git a/shell/preload/sitecustomize.py b/shell/preload/sitecustomize.py index 9e8b631d..67c48d38 100644 --- a/shell/preload/sitecustomize.py +++ b/shell/preload/sitecustomize.py @@ -54,10 +54,10 @@ def run(): task_before = os.getenv("task_before") if task_before: - command += f" && echo -e '执行前置命令\n' && eval \"{task_before}\" && echo -e '\n执行前置命令结束\n'" + command += f" && echo -e '执行前置命令\n' && eval '{task_before}' && echo -e '\n执行前置命令结束\n'" python_command = "PYTHONPATH= python3 -c 'import os, json; print(json.dumps(dict(os.environ)))'" - command += f' && echo "{split_str}" && {python_command}"' + command += f" && echo -e '{split_str}' && {python_command}\"" res = subprocess.check_output(command, shell=True, encoding="utf-8") output, env_str = res.split(split_str)