Forum Discussion

bistritapcv's avatar
bistritapcv
Contributor
6 years ago

Connecting to a pid rather than to a process

Previously I was using TC 12 and C#

 

     Connect.Sys["Process"]("java", 900000);
     rootNode = driver.WaitProcess("java");

 

to connect to my Java process I start up.  But lately there have been multiple instances of Java.  For instance when this tries to run on the Jenkins machine, there is a Jenkins java process.

 

I am using C# so I was able to get the PID of the Java Process (integer) to which I would like to connect.

But I am not sure how to do this.  I tried

 

     Connect.Sys["Pid"](javapid, 90000);

 

where javapid is the pid, but it gave me an unknown name error.  So does anyone have any suggestions?

And please don't tell me to use TestLeft.

 

(

  driver.waitProcess(processName)   just does a 

  return Connect.Sys["WaitProcess"](processName, timeout);

)

 

Thanks

  • I'm not sure to understand the need but perhaps this do your job ?

     

    function GetMyPID(ProcessName, ProcessId) {
      var p = Sys.FindChild("ProcessName", ProcessName);
      var result = -1;
      while (p.Exists) {
        if (p.Id == ProcessId) {
          result = p.Id;
          break;
        } 
    p = Sys.FindChild("ProcessName", ProcessName); } return result; }
  • BenoitB's avatar
    BenoitB
    Community Hero

    I'm not sure to understand the need but perhaps this do your job ?

     

    function GetMyPID(ProcessName, ProcessId) {
      var p = Sys.FindChild("ProcessName", ProcessName);
      var result = -1;
      while (p.Exists) {
        if (p.Id == ProcessId) {
          result = p.Id;
          break;
        } 
    p = Sys.FindChild("ProcessName", ProcessName); } return result; }
  • Man, it's been like half a year since I asked ;-)  I figured out some other way but now I do not remember.

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      bistritapcv 

      Perhaps, once you find the solution, you could post it and mark it solved?  That would avoid "resurrection" of dead topics like this. :-)

      • sonya_m's avatar
        sonya_m
        SmartBear Alumni (Retired)

        Thanks everyone for participation:smileyhappy:

         

        Since this got ressurected I'll go ahead and mark BenoitB's answer as a solution for future reference.