Forum Discussion

guillaume's avatar
guillaume
Contributor
13 years ago

Calling WaitProcess method from a finalize routine in a ScriptExtension

Hi.



I have a problem with the Finalize routine in a script extension I am trying to create.

The purpose is to close a list of processes at the really end of the execution.



In order to that, the user pushes in a array the process name he wants to close automatically at the end.

Then, when the script extension is unloading from TestExecute environment, the finalize routine does something like that :



function Finalize()

{

   try{

        for (var i = 0; i < arrProcess.length; i++){

            var objProcess = Sys.WaitProcess(arrProcess, 500);

            objProcess.Close();

        }

    }catch(e){

        Log.Error(e.message);

    }

}




I am facing two different problems there :


  • The main one is that the WaitProcess raised an unknown error, without name nor description.

  • I am unable to log errors from the exception caught.


I guess that this is not something that should be done, but I am really trying to make this work.



Do you have any idea about how to solve those errors ?



Regards,



Guillaume.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Is it the WaitProcess that returns the error or the Close method?  



    The reason I ask that is that if the process being referenced by the arrProcess(i) doesn't exist, it won't have a close method.  You should do an "If exists" test first to make sure the process exists before attempting to close it.



    Otherwise, the only other thing I can suggest is to make sure that your array is actually returning a string.  WaitProcess requires a string for the first parameter.  To debug, try adding a "Log.Message" call before your assignment to see if it returns as a string.



    Of course, the obvious question is whether or not arrProcess is propulated, how it's populated, with what, etc., because if the finalize routine is attempted without doing anything with that object, it won't work.



    As for logging the error... the try/catch should work, assuming that the error is one that raises an exception and is not a syntax or other error in your code.  Try putting that routine in a straight-up script routine and run it directly without putting it in your extension and see what happens.