Ask a Question

Connecting to a pid rather than to a process

SOLVED
bistritapcv
Contributor

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

7 REPLIES 7
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; }

Un sourire et ça repart

tristaanogre
Esteemed Contributor

@BenoitB  Suggestion will work with one change.  Replace "FindChild" with "FindAllChildren".  FindChild will return only one process... and only the "top" one in the list.  So, use "FindAllChildren" and loop through the array of found processes until the process object found has the same PID as the one you're looking for, then break.

 

See documentation on FindAllChildren

 

https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/findal...


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

True, but i can affirm it will work as i've written, use it since a loong time.. (To terminate processs still executing with a certain PID).

Lot of the underneath Window API manage themself the picking of next sibling when they are called in loop.

 

 

Un sourire et ça repart

bistritapcv
Contributor

Man, it's been like half a year since I asked 😉  I figured out some other way but now I do not remember.

@bistritapcv 

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


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
sonya_m
SmartBear Alumni (Retired)

Thanks everyone for participationSmiley Happy

 

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


Sonya Mihaljova
Community and Education Specialist

Looks like that may do it

cancel
Showing results for 
Search instead for 
Did you mean: