From 738fe04ce45f50d1703dc57953661f0f02b61c49 Mon Sep 17 00:00:00 2001 From: whyour Date: Sat, 13 Jul 2024 23:53:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20js=20py=20=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=88=86=E5=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/env.ts | 15 ++++++++++----- shell/otask.sh | 11 +++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/back/services/env.ts b/back/services/env.ts index 27a0b76d..345bb065 100644 --- a/back/services/env.ts +++ b/back/services/env.ts @@ -210,13 +210,18 @@ export default class EnvService { .replace(/'/g, "'\\''") .trim(); env_string += `export ${key}='${value}'\n`; - const _env_value = `'${group + const _env_value = `${group .map((x) => x.value) .join('&') - .replace(/\\/g, '\\\\') - .replace(/'/g, "\\'")}'`; - js_env_string += `process.env.${key}=${_env_value};\n`; - py_env_string += `os.environ['${key}']=${_env_value}\n`; + .replace(/\\/g, '\\\\')}`; + js_env_string += `process.env.${key}=\`${_env_value.replace( + /\`/g, + '\\`', + )}\`;\n`; + py_env_string += `os.environ['${key}']='''${_env_value.replace( + /\'/g, + "\\'", + )}'''\n`; } } } diff --git a/shell/otask.sh b/shell/otask.sh index 290a293a..7b74b82f 100755 --- a/shell/otask.sh +++ b/shell/otask.sh @@ -87,8 +87,11 @@ check_server() { } env_str_to_array() { + . $file_env local IFS="&" read -ra array <<<"${!env_param}" + array_length=${#array[@]} + clear_env } clear_non_sh_env() { @@ -123,7 +126,7 @@ handle_env_split() { fi env_str_to_array - local tempArr=$(echo $num_param | sed "s/-max/-${#array[@]}/g" | sed "s/max-/${#array[@]}-/g" | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g") + local tempArr=$(echo $num_param | sed "s/-max/-${array_length}/g" | sed "s/max-/${array_length}-/g" | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g") local runArr=($(eval echo $tempArr)) array_run=($(awk -v RS=' ' '!a[$1]++' <<<${runArr[@]})) } @@ -229,16 +232,20 @@ main() { isJsOrPythonFile="true" fi if [[ -f $file_env ]]; then + get_env_array if [[ $isJsOrPythonFile == 'true' ]]; then export NODE_OPTIONS="${NODE_OPTIONS} -r ${preload_js_file}" export PYTHONPATH="${PYTHONPATH}:${dir_preload}" else - get_env_array . $file_env fi fi if [[ $1 == *.js ]] || [[ $1 == *.py ]] || [[ $1 == *.pyc ]] || [[ $1 == *.sh ]] || [[ $1 == *.ts ]]; then + if [[ $1 == *.sh ]]; then + timeoutCmd="" + fi + case $# in 1) run_normal "$1"