IDL编译不会返回失败状态

时间:2016-08-31 09:00:16

标签: shell idl-programming-language

我对IDL没有多少经验,但我需要修复一个错误,在编译失败状态需要返回到调用脚本。

    cat << ENDCAT > something.pro

    PRINT, "Start"

    PRINT, "Compiling functions needing early compile"
    @do_early_func

    PRINT, "Compiling remaining functions"
    @do_other_func

    PRINT, "Running: resolve_all"
    resolve_all

    EXIT

    ENDCAT

    setenv IDL_STARTUP something.pro

    $IDL_DIR/bin/idl

以上内容存在于名为 make_program 的脚本中,该脚本由另一个名为 build_script 的脚本调用

我面临的问题是,即使&#39; resolve_all&#39;导致编译失败, make_program 总是向 build_script 返回true,这使得它认为编译成功时实际上并没有。如何将故障状态返回给调用脚本?

2 个答案:

答案 0 :(得分:0)

The EXIT routine has a STATUS keyword that can return the exit status of the script. So something like:

exit, status=status_code

To determine if RESOLVE_ALL completed correctly, you may need to do a CATCH block. The easiest way is probably to wrap RESOLVE_ALL in your own routine that has an ERROR keyword that returns whether the RESOLVE_ALL succeeded.

答案 1 :(得分:0)

我不知道我选择了哪个,但你需要两个例程:

function validate_syntax_helper, routineName

  compile_opt strictarr, hidden

  catch, error
  if (error ne 0) then return, 0

  resolve_routine, routineName, /either, /compile_full_file
  return, 1

end

function validate_syntax, routineName

  compile_opt strictarr, hidden

  oldquiet = !quiet
  !quiet = 1

  catch, error
  if (error ne 0) then return, 0

  ; Get current directory
  cd, current=pwd

  o = obj_new('IDL_IDLBridge')
  o->execute, '@' + pref_get('IDL_STARTUP')
  ; Change to current directory
  o->execute, 'cd, ''' + pwd + ''''
  ; Validate syntax
  cmd = 'result = validate_syntax_helper(''' + routineName + ''')'
  o->execute, cmd
  result = o->getVar('result')
  obj_destroy, o

  !quiet = oldquiet

  return, result

end

然后,您可以调用validate_syntax,它可以在可编译时返回1,而在0时则返回execute。我不认为这可以在IDL虚拟机中使用,因为它使用resolve_all,但这对您来说并不重要。您必须在所有要编译的例程上手动运行此操作,而不是运行moment