IPC

Y

Yannick Turgeon

Hi,

I'm relatively new to Python. I'm using 2.3.4 on W2K.

What I want to do is to start a program and interact with it. Say my program
is FTP, I want to start FTP then send the commande "open x.x.x.x" then look
for the answer (if the connection is opened or not), then do something
dependant of the success or error.

I tried with popen3. The problem I got with this: it seems that I have to
end the program before being able to read the output. Or maybe I'm not using
it correctly. I do test the communication with FTP exec. but it will be a
custom program in real. Here is my code:


def test(self):
cmd = "ftp"
r, w, e = popen2.popen3(cmd)

cmd = "?\n" # A simple FTP commande
w.write(cmd)
w.flush()

# That is what I would like but it's hanging here. I have to remove
this group and read at the end.
for line in e.readlines():
# Do something conditionnal to the result of "line"
pass
for line in r.readlines():
# Do something conditionnal to the result of "line"
pass


cmd = "quit\n"
w.write(cmd)
w.flush()

for line in e.readlines():
print line
for line in r.readlines():
print line

w.close()
r.close()
e.close()
 
Y

Yannick Turgeon

Larry,

As I said, I use FTP only to test the IPC and give here a known example.
It's in fact with a custom program that I have to communicate.

Any help in this regard?

Yannick
 
F

Fernando Perez

Yannick said:
As I said, I use FTP only to test the IPC and give here a known example.
It's in fact with a custom program that I have to communicate.

Any help in this regard?

google('python expect interactive') # expect is the key word here

hth,

f
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top