Forum Discussion

rushikesh's avatar
rushikesh
Contributor
7 years ago

How to avoid error in log when code to check process.Exists is executed.

Hi,

 

I am running below code

 

function KillProcess(App)
{

// Checks whether the process is closed
if (Sys.Process(App).Exists)
// Terminates the process
{
process.Terminate();
}

}

 

 

below is function used to run.

function TestKillProcess()
{
KillProcess("KillDlg")
}

 

Problem i am facing is that when KillDlg.exe is not running it logs error in log file saying KillDlg.exe was not found.

I want Test Complete to kill KillDlg.exe when it is present, otherwise do nothing, not even log error in log file.

If logs Message then no problem but don't want error.

 

Any help is appreciated.

 

Regards,

Rushikesh Kadam.

 

 

 

1 Reply

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Change your code to the following:

    function KillProcess(App){
    var process;
    
    process = Sys.WaitProcess(App, 10000);
    
    // Checks whether the process is closed
    if (process.Exists)
    // Terminates the process
    {
        process.Terminate();
        }
    
    }
    

     When detecting existence, it's best to use the appropriate "Wait" method... in this case, WaitProcess will look for the process, in my example, for up to 10 seconds.  If the process returns within those 10 seconds, Exists is true.  Otherwise, a stub object is returned with Exists  as false.