source vars.exp
source procs.exp

# NO Authenticate window
# set env(TTA_AllowThirdTierDialog) "none"  
# Domain to Use
#set env(TTA_DomainName) ""

set env(tta_username) $args(username) 
set env(tta_password) $args(password)
set env(tta_host) $args(host)    

# Uncomment to turn on the extra debug - lots of information so default is off
# startdebug

set args(DirCachePath) $env(TTADATADIR)
append  args(DirCachePath) "/log/cache/"
set pos [expr $spos+1]
set lon [string last ".log" $env(TTA_LOGFILE)]
set args(ExpFile) $args(DirCachePath)[string range $env(TTA_LOGFILE) $pos $lon]exp
set args(scan_ttacachePath) "STTATOOLSDIR"
set args(scan_ttacacheCmd) "scanttacache"

system "$args(scan_ttacachePath)/$args(scan_ttacacheCmd) >$args(ExpFile)"
system "chown bin:bin $args(ExpFile)"
source $args(ExpFile)
system "rm -f $args(ExpFile)"

if { $msg_access != "" } {
     send_error "$msg_access"
     exit $exitCode(ErrApplicationServerLoginFailed)
}

# Try to optimise 
optimiselaunch

#Check the status of the third tier
probe_third_tier

# Normal launch procedure
initialise
#preexpbefore
if {$env(TTA_COMMAND) != ""} {
    if { ($env(TTA_CONNECTIONSERVICE) != "shell" && $env(TTA_CONNECTIONSERVICE) != "exec" && $env(TTA_CONNECTIONSERVICE) != "rcmd") || ($locallaunchflag == 1) } {
        login
	startshells
    } else {
	# For the exec and shell services there is no interaction
	# therefore we ensure prompt detection always succeeds by
	# matching anything
	set prompts(prompt) ""
	expect *
    } 
    if { ($env(TTA_CONNECTIONSERVICE) != "ssh") } {
        if [ catch { runxauth } ] {
            send_log "$errorStrings(runxauth_failed)"
        }
    }
    setupenv
    if { $appextra_cmd != "" } { 
         append  env(TTA_Arguments) " $appextra_cmd "  
     #   send -s "TTA_Arguments=\"$env(TTA_Arguments)\" ; export TTA_Arguments\n"  
    }
    mansetupenv
    runauxcommands
    runmaincommand
} else {
    expect "\n"
    scriptcomplete
}
