[Tutor] Popen

G Kiran goki75@vsnl.net
Tue Aug 5 14:31:02 EDT 2003


the following is the code...
the b.read from the pipe doesnot return and blocks there itself...since
cmd.exe does not end on its own
is there a way to open a two way pipe...so i can send and "exit" command to
end the shell...or write and read without blocking?



import socket
import os

s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind(("",81))
s.listen(5)
conn,addr=s.accept()
cmd=""
while (1):
    onechar=conn.recv(1)
    if not(onechar== '\n'): cmd=cmd+onechar
    else:
        a=popen("\\windows\\system32\\cmd.exe "+cmd)
        result=b.read()
        conn.send(result)
        cmd=""





More information about the Tutor mailing list