Announcement

Collapse
No announcement yet.

FILE close bug

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • FILE close bug

    It appears that there is a bug in the close method of the File object.

    I open a file and read it's contents then invoke the close() method. It appears that the close method throws an exception (I can only guess) and terminates the current call thread all the way back to main.

    In my attached exampl the "before close" prints but the "after close" never does, nor does the "EMA plot:".

    Has anyone seen this? Is this a known bug? I've reproduced this on two different machines with the attached script.

    Thx,
    Mike

    Hmm attaching a .efs doesn't seem to work. Here it is:

    /***************************************

    EMA

    ************************************************** ***************/

    var MALen = 125;
    var bInit = false;

    function preMain() {
    debugPrintln("EMA preMain");

    setComputeOnClose(true);
    setPriceStudy(true);
    setStudyTitle("EMA: " + MALen);
    setDefaultBarThickness(2, 1);
    setCursorLabelName("EMA.efs", 0);

    }


    function main() {

    //Initialization
    if (bInit == false) {
    xMA = ema(MALen);
    bInit = true;
    }
    var nEMA = xMA.getValue(0);
    var plot;
    plot = nEMA;

    var cb = getCurrentBarIndex();

    if (-1 == cb)
    StatusCheck();

    debugPrintln("EMA plot:" + plot);

    return plot;
    }

    function StatusCheck() {
    var f = new File("RequestTradingStatus.txt");
    if (f.exists()) {
    f.open("rt");
    if (f.isOpen()) {
    var f = f.read(1);
    if (1 == f) {
    debugPrintln("StatusCheck 1");
    } else {
    debugPrintln("StatusCheck 0");
    }
    // Important, closing a file not open appears to abort the
    // outer function call
    debugPrintln("before close");
    f.close();
    debugPrintln("after close");
    }
    }
    }
    Last edited by mikem2006; 05-21-2008, 11:46 AM.

  • #2
    Your Code is buggy

    Mike,

    You have several errors in your code creating the behavior you are seeing.


    1. you are redefining the file object you are creating before you close it.

    2. the file object methods are not read() and write(), rather they are writeln() and readln()

    I corrected these below and have run it and it seems to work now. Try this, it should work sufficiently to get you past your bug.

    Hope this helps.






    PHP Code:
    /***************************************

    EMA

    **************************************************
    ***************/

    var MALen 125;
    var 
    bInit false;

    function 
    preMain() {
     
    debugPrintln("EMA preMain");

     
    setComputeOnClose(true);
     
    setPriceStudy(true);
     
    setStudyTitle("EMA: " MALen);
     
    setDefaultBarThickness(21);
     
    setCursorLabelName("EMA.efs"0);

    }


    function 
    main() {

     
    //Initialization
     
    if (bInit == false) {
      
    xMA ema(MALen);
      
    bInit true;
     }
     var 
    nEMA xMA.getValue(0);
     var 
    plot;
     
    plot nEMA;

     var 
    cb getCurrentBarIndex();

     if (-
    == cb){
      
    StatusCheck();
     }
     
    //~ debugPrintln("39:EMA plot:" + plot);

     
    return plot;
    }

    function 
    StatusCheck() {
     var 
    = new File("RequestTradingStatus.txt");
     
    debugPrintln("45:f.exists()=" f.exists());
     if (!
    f.exists()){
      
    f.open("wt");
      
    f.writeln("1");
      
    f.close();
     }
     if (
    f.exists()) {
      
    f.open("rt");
      if (
    f.isOpen()) {
      
    //~ var f = f.readln();   // PROBLEM YOU OVERWROTE THE "f" variable
      
    var knuckle f.readln();
      if (
    == knuckle) {
      
    debugPrintln("57: StatusCheck 1");
      } else {
      
    debugPrintln("59: StatusCheck 0");
      }
      
    // Important, closing a file not open appears to abort the
      // outer function call
      // PROBLEM YOU OVERWROTE THE "f" variable
      
    debugPrintln("64:before close");
      
    f.close();
      
    debugPrintln("66:after close");
      }
     }

    Attached Files

    Comment


    • #3
      Thx

      Ah heck I missed that. Thx.

      FYI though, read and write are also methods of the File object in addition to readln/writeln.

      Comment


      • #4
        Mike,

        Your are most welcome. I didn't believe those methods were supported, but after testing, they work nicely.

        Thanks for the feedback, I wouldn't have revisited this functionality otherwise.

        Comment

        Working...
        X