Forum Discussion

jonas644's avatar
jonas644
Occasional Contributor
15 years ago

Process not found.

Hello,

This is probably an easy fault that i've made but i just can't see it.



When i run this and the process doesn't exists i get a error "Process not found".


  if ( Sys["Process"]("myprocess")["Exists"] )

  {

    Sys["Process"]("myprocess")["Terminate"]();

  }


But if the process exists it'll work perfectly.

So i don't want this function to return a Error to my log. Any tips?



The reason why i want to do this is because i can't start the application if a instance is already running.

So i wanted to make a control to check if it's running before starting a new instance.



BR

Jonas

4 Replies


  • Hi Jonas,





    Use the WaitProcess method instead. Also, instead of the Terminate method, use Close:







    function CloseProcess()

    {

      var PName = "myprocess";

      var p = Sys["WaitProcess"](PName, 1000, 1);

      while (p["Exists"]) {

        p["Close"]();

        p = Sys["WaitProcess"](PName, 1000, 1);    

      } 

    }




  • jonas644's avatar
    jonas644
    Occasional Contributor
    Hello Allen,



    Thanks for the tip. But it didn't work.

    If TestComplete can't find myprocess it give me a error in my Log.




    function CloseProcess()

    {

      var Client = Sys["Process"]("WorkRecordingClient") - This line gives error in Log if process not exists.

      var p = Sys["WaitProcess"]( Client, 1000, 1 );

      while (p["Exists"])

      {

        p["Close"]();

        p = Sys["WaitProcess"]( Client, 1000, 1 );

      }

    }


    I made this function and called it from my run_application function.

    Is there any way to do my scenario? Can i catch the Error "Process not found"? 



    It workes perfectly when the process is started. But if not i get the error.

  • Hi Jonas,





    Do not address the process by Sys["Process"]("ProcessName"): instead of







    var Client = Sys["Process"]("WorkRecordingClient")







    just use the name of the process:







    var Client = "WorkRecordingClient";

  • jonas644's avatar
    jonas644
    Occasional Contributor
    Hello Allen,



    That solved my issue. Thanks for the assistance =)



    BR

    //Jonas