From: Syver E. <syv...@on...> - 2002-01-26 23:37:45
|
This should be a bit better. I tried first to make a subclass of org.python.core.PyFile but I got an error message trying to assign the self._process attribute to self. Anyone knows why? I thought one could assign attributes to subclasses of Java classes, but then I am pretty new in the jython game. class _ProcessFile: def __init__(self, stream, process, name): self._file = org.python.core.PyFile(stream, "'%s'" % name) self._process = process def __getattr__(self, name): return getattr(self._file, name) def __repr__(self): return `self._file` def close(self): self._file.close() return self._process.waitFor() or None def _startProcess(path): r = java.lang.Runtime.getRuntime() try: p = r.exec(path) return p except java.io.IOException, exc: raise OSError(0, exc.toString()) def popen(path, mode='r'): p = _startProcess(path) if mode == 'r': return _ProcessFile(p.getInputStream(), p, path) elif mode == 'w': return _ProcessFile(p.getOutputStream(), p, path) else: raise OSError(0, "Invalid mode", mode) def popen2(path): p = _startProcess(path) return (_ProcessFile(p.getInputStream(), p, path), _ProcessFile(p.getOutputStream(), p,path)) def popen3(path): p = _startProcess(path) return (_ProcessFile(p.getInputStream(), p, path), _ProcessFile(p.getOutputStream(),p, path), _ProcessFile(p.getErrorStream(), p, path)) -- Vennlig hilsen Syver Enstad |