Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > IPC

Reply
 
 
Yannick Turgeon
Guest
Posts: n/a
 
      07-27-2004
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()
----------------------

Anybody can help? Thanks for your time.

Yannick


 
Reply With Quote
 
 
 
 
Larry Bates
Guest
Posts: n/a
 
      07-27-2004
Python has built in support for ftp (see ftplib)
use it instead of trying to "communicate" with
external FTP program.

http://www.python.org/doc/current/li...le-ftplib.html

You can catch any exceptions (like failure to connect)
by using python try:/except: blocks.

HTH,
Larry Bates
Syscon, Inc.

"Yannick Turgeon" <(E-Mail Removed)> wrote in message
news:Z6wNc.21572$(E-Mail Removed). ..
> 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()
> ----------------------
>
> Anybody can help? Thanks for your time.
>
> Yannick
>
>



 
Reply With Quote
 
 
 
 
Yannick Turgeon
Guest
Posts: n/a
 
      07-27-2004
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

"Larry Bates" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Python has built in support for ftp (see ftplib)
> use it instead of trying to "communicate" with
> external FTP program.
>
> http://www.python.org/doc/current/li...le-ftplib.html
>
> You can catch any exceptions (like failure to connect)
> by using python try:/except: blocks.
>
> HTH,
> Larry Bates
> Syscon, Inc.
>
> "Yannick Turgeon" <(E-Mail Removed)> wrote in message
> news:Z6wNc.21572$(E-Mail Removed). ..
> > 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()
> > ----------------------
> >
> > Anybody can help? Thanks for your time.
> >
> > Yannick
> >
> >

>
>



 
Reply With Quote
 
Fernando Perez
Guest
Posts: n/a
 
      07-28-2004
Yannick Turgeon wrote:

> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File Sharing IPC$ Problem =?Utf-8?B?SmltIE1jQ29sbA==?= Wireless Networking 7 10-25-2004 09:31 PM
IPC Mechanism Named pipes or Windows messages or sthg else ? piyush ASP .Net 0 07-14-2004 02:41 PM
Using IPC::open2 under mod_perl Antonio Perl 0 05-17-2004 12:11 PM
IPC::Run and hanging pipes Brian Hann Perl 1 12-11-2003 08:41 PM
open, ipc, and return codes gary Perl 3 09-18-2003 12:17 AM



Advertisments