How to get Batch task attached to a script to WORK in X3?

SOLVED

Hi There,

                Would anyone help me?

                I am trying to run a simple batch task to generate a log file, but i can't get it to work. It seems to be executing ,but no trace file is generated. This code work fine on the script editor, but doesn't work when i run it as a batch file.

Please code and images below for more insight:

Gosub OUVRE_BATCH

End

$OUVRE_BATCH
          Gosub EXEC
Return


$EXEC

Local Integer YOPEN
Local Integer YOK


# Check if a trace file is already open, if it isn't, then open one
YOPEN = 2


If GTRACE = ""
             Raz YOPEN
             Call OUVRE_TRACE("EXPDAT Changed") From LECFIC
Endif


   # create some type of separator in the file
              Call ECR_TRACE("-------------------------",0) From GESECRAN
  # perform your process, in this example, I use YOK to know if the process
  # was successful or wrong

If YOK = 2
            Call ECR_TRACE("The Expiration Date change was valid",0) From GESECRAN
Else
           Call ECR_TRACE("The Expiration Date change was NOT valid, please verify.",1) From GESECRAN

Endif


# if the file was already open, don't close it
If YOPEN <> 2

     # close the log file
          Call FERME_TRACE From LECFIC # display the log file
          Call LEC_TRACE From LECFIC


Endif

Return