'Run external Python script'

def cmd_run_external(self, full_path):

    def format_error(path, e):
        s = 'Can\'t    call    "main"    from    "{path}"\n DCTB {err_name}:    {err}'
        return s.format(path=path, err_name=e.__class__.__name__, err=e)
    module_name = os.path.splitext(os.path.basename(full_path))[0]
    dir_path = os.path.dirname(full_path)
    err_str = ''
    local_stdout = io.BytesIO()
    old_stdout = sys.stdout
    sys.stdout = local_stdout
    sys.exc_clear()
    try:
        module = _import_module(module_name, dir_path)
        module.main(self)
    except ImportError as e:
        err_str += format_error(full_path, e)
    except:
        (exc_type, exc_value, exc_traceback) = sys.exc_info()
        err_str += traceback.format_exc()
        err_str += format_error(full_path, exc_type(exc_value))
    finally:
        sys.exc_clear()
        sys.stdout = old_stdout
        local_stdout.close()
    return (local_stdout.getvalue() + err_str)
