How to check if Pexpect child already exist?
d at davea.name
Wed Dec 5 09:20:26 CET 2012
On 12/05/2012 02:41 AM, Thomas Elsgaard wrote:
> Hi List
> I am wondering, how can i check if child already exist before i spawn
By definition, before you call the spawn, the child doesn't exist. So
presumably you must mean something else.
> child.isalive() cannot be done on child before it has been spawned.
> import pexpect
> child=pexpect.spawn('ssh mysurface at 192.168.1.105')
All we have to do is guess what you really mean. Do you mean you want
to know if there are any instances of ssh running? Regardless of how
they got spawned, or from what process? Or are you trying to determine
if the current process (your script) has any children, of any kind? Or
Also, you should probably tell what OS and Python versions you're running.
One approach on Linux might be to capture the output of 'ps aux' and
parse it for whatever match criteria you have.
More information about the Python-list