Re: Pexpect question.
On Wed, 02 Apr 2008 19:57:31 -0600, Paul Lemelle <[EMAIL PROTECTED]> wrote: > Jorgen, > > Thanks for your reply. > > The ssh function is just a small part of what I would like to > accomplish. And yes, chk is undefined, I was trying to figure out why > control was not being returned from the sshcon funciton. OK. Hope my note helped. > I looked for pexpect doucment on http://www.noah.org/wiki/Pexpect, but > the documentaiton link appear to be broken. Could you recommend > another site? As I recall it, the online documentation is just the documentation from the Python module itself, HTML-formatted. You can simply type "pydoc pexpect" and get the reference manual. I think it's pretty good. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! -- http://mail.python.org/mailman/listinfo/python-list
Re: Pexpect question.
Jorgen, Thanks for your reply. The ssh function is just a small part of what I would like to accomplish. And yes, chk is undefined, I was trying to figure out why control was not being returned from the sshcon funciton. I looked for pexpect doucment on http://www.noah.org/wiki/Pexpect, but the documentaiton link appear to be broken. Could you recommend another site? Thanks, Paul On 30 Mar 2008 21:39:46 GMT, Jorgen Grahn <[EMAIL PROTECTED]> wrote: >On Fri, 28 Mar 2008 08:12:36 -0700 (PDT), Paul Lemelle <[EMAIL PROTECTED]> >wrote: >> I am trying separate a script that users pexpect into >> various functions within the same expect session. The >> problem is that the function does not return control >> back Main. > >I do not understand what that sentence means. > >> Any insight into this issue would be >> greatly appreciated. Below is sample code of the >> problem. > >First, what is the purpose of this program? It seems to be a more >tedious way to get an ssh login to some Unix host. Ssh can be >configured to do many things; maybe you do not need Python at all? > >Second, it will fail as soon as you use the undefined object 'chk'. > >Third, if "not return control back Main" means "sshcon() does not >return", then it is by design. You call go.interact(), which hands >over control to the user until he types an escape sequence. See the >pexpect documentation. > >Fourth, sshcon() does not handle the full dialogue ssh can give you. >If you get "are you sure you want to connect" etc, you will hang until >pexpect.TIMEOUT is thrown. > >I have reformatted the source code to be more readable: > >> import pexpect >> >> def sshcon(host, password): >> go = pexpect.spawn ('/usr/bin/ssh -l root %s ' % host) >> go.expect ('Password: ') >> go.sendline (password) >> go.interact() >> >> #get node info for both clusters. >> C1_node = raw_input("Enter the ip address for node on cluster 1: ") >> C1_pass = raw_input("Enter the password for the node on cluster 1: ") >> >> sshcon(C1_node, C1_pass) >> >> #go to the path >> chk.expect('# ') >> chk.sendline('ls') >> >> chk.interact() > >/Jorgen -- http://mail.python.org/mailman/listinfo/python-list
Re: Pexpect question.
On Fri, 28 Mar 2008 08:12:36 -0700 (PDT), Paul Lemelle <[EMAIL PROTECTED]> wrote: > I am trying separate a script that users pexpect into > various functions within the same expect session. The > problem is that the function does not return control > back Main. I do not understand what that sentence means. > Any insight into this issue would be > greatly appreciated. Below is sample code of the > problem. First, what is the purpose of this program? It seems to be a more tedious way to get an ssh login to some Unix host. Ssh can be configured to do many things; maybe you do not need Python at all? Second, it will fail as soon as you use the undefined object 'chk'. Third, if "not return control back Main" means "sshcon() does not return", then it is by design. You call go.interact(), which hands over control to the user until he types an escape sequence. See the pexpect documentation. Fourth, sshcon() does not handle the full dialogue ssh can give you. If you get "are you sure you want to connect" etc, you will hang until pexpect.TIMEOUT is thrown. I have reformatted the source code to be more readable: > import pexpect > > def sshcon(host, password): > go = pexpect.spawn ('/usr/bin/ssh -l root %s ' % host) > go.expect ('Password: ') > go.sendline (password) > go.interact() > > #get node info for both clusters. > C1_node = raw_input("Enter the ip address for node on cluster 1: ") > C1_pass = raw_input("Enter the password for the node on cluster 1: ") > > sshcon(C1_node, C1_pass) > > #go to the path > chk.expect('# ') > chk.sendline('ls') > > chk.interact() /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! -- http://mail.python.org/mailman/listinfo/python-list
Pexpect question.
I am trying separate a script that users pexpect into various functions within the same expect session. The problem is that the function does not return control back Main. Any insight into this issue would be greatly appreciated. Below is sample code of the problem. Thanks, Paul import pexpect def sshcon(user, password): go = pexpect.spawn ('/usr/bin/ssh -l root %s '% (user)) go.expect ('Password: ') go.sendline (password) go.interact() #get node info for both clusters. C1_node = raw_input("Enter the ip address for node on cluster 1: ") C1_pass = raw_input("Enter the password for the node on cluster 1: ") sshcon(C1_node, C1_pass) #go to the path chk.expect('# ') chk.sendline('ls') #chk = pexpect.spawn('ls') # veriy that you are connected chk.interact() Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping -- http://mail.python.org/mailman/listinfo/python-list
Re: pexpect question....
Hi, While I continue to look at the problem, I thought I would post more details. In a sense, this is more of a UNIX issue. I have a python script that uses pexpect to spawn a child process (p1). The python script then goes ahead and does a "tail --pid=p1". Assuming that I do close(wait=0), P1 completes and gets stuck in zombie status. The python script is also stuck because "tail" will not return until zombie P1 goes away. So each is waiting for the other to go away resulting in a deadlock. Apparently, when close(wait=0) is done, all that pexpect does is that it wouldn't call wait() on the spawned process anymore. I was looking for a solution where pexpect also should be able to tell kernel that it doesn't care about child process's exit status. Note that this is different from not doing "wait". I think this can be achieved by ignoring SIGCLD on SVR4 systems but I am not sure what is the (expected) behaviour on posix/linux. Unfortunately, only parent process can control this behaviour. So my questions are two fold. 1) What is the best way (preferably a generic UNIX way) for a parent process to inform kernel that it is not interested in child process's exit status? 2) How can this be achieved in pexpect module since it is spawning the child process in my case. As I said, this is more of a UNIX question rather than python one. Thanks, Raghu. -- http://mail.python.org/mailman/listinfo/python-list
Re: pexpect question....
[EMAIL PROTECTED] wrote: > Currently, I am spawning a new thread > that just does pexpect_spawned_child.close(wait=1). It seems to work in > some cases but the child process is occassionally getting deadlocked. I think your only cross-platform option will be to fix the child process to die nicely instead of trying to find better ways kill it. -Jonathan -- http://mail.python.org/mailman/listinfo/python-list
Re: pexpect question....
Hi, I actually replied saying that the process dies when close(wait=0) is done (the reply doesn't show up yet). It is not correct. The process actually runs but ends up in zombie status (defunct). Raghu. -- http://mail.python.org/mailman/listinfo/python-list
Re: pexpect question....
> "[EMAIL PROTECTED]" == [EMAIL PROTECTED] com <[EMAIL PROTECTED]> writes: > Hi, > I am using pexpect to spawn an interactive program and wait for > particular string in its output. It works fine but once I get this > required information, I really don't care about the child process > anymore. I would effectively want to "detach" from it. How about just calling close(), i.e. without wait=1? No need to spawn a new thread. Ganesan -- Ganesan Rajagopal (rganesan at debian.org) | GPG Key: 1024D/5D8C12EA Web: http://employees.org/~rganesan| http://rganesan.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
pexpect question....
Hi, I am using pexpect to spawn an interactive program and wait for particular string in its output. It works fine but once I get this required information, I really don't care about the child process anymore. I would effectively want to "detach" from it. Is there any way to do such thing in pexpect? I did read pexpect's doc but couldn't find any information in this regard. Currently, I am spawning a new thread that just does pexpect_spawned_child.close(wait=1). It seems to work in some cases but the child process is occassionally getting deadlocked. # strace -p 23159 Process 23159 attached - interrupt to quit write(2, "H_235J Task 4 being run as INCR"..., 72 It just sits there indefinitely. Python is 2.3.3 and the OS is SuSe 9.1. Thanks, Raghu. -- http://mail.python.org/mailman/listinfo/python-list