我正在为sockets编写一个包装类,以便可以将它用作一个类似于文件的对象,用于管道化到使用subprocess.Popen()
创建的进程的stdin
和{
def do_task():
global s #The socket
class sockIO():
def __init__(self, s):self.s=s
def write(self, m): self.s.send(m)
def read(self, n=None): return self.s.read() if n is None else self.s.read(n)
def fileno(self): return self.s.fileno()
#stdio=s.makefile('rw')
stdio=sockIO(s)
cmd = subprocess.Popen('cmd', shell=True,
stdout=stdio, stderr=stdio,
stdin=stdio)
我没有使用socket.makefile()
,因为它给出了一个io.UnsupportedOperation: fileno
错误,但是通过我现在的代码,我在Windows上得到了以下错误(在Linux上可以正常工作):
根据关于
socket.fileno()
的Python文档,声明这在Windows中不起作用。引自Python Documentation:注意:
上面的代码可以在Linux和其他*nix系统中工作。在
相关问题 更多 >
编程相关推荐