From: Robert W. B. <rb...@di...> - 2001-03-29 01:22:42
|
Hi Chris, On Wed, 28 Mar 2001, Chris Meyers wrote: > Is there an easy (or not so easy) way to run a system command in jython? yes, Runtime. > tried to run os.system(xpdf foo.pdf) and I get this: > > AttributeError: class 'org.python.modules.os' has no attribute 'system' There is no os.system in Jython. Brian Z recently posted the Runtime info/examples that will help. Found at: http://www.geocrawler.com/lists/3/SourceForge/7017/75/5376252/ - and - http://www.geocrawler.com/lists/3/SourceForge/7017/75/5376101/ I haven't really looked at this, but if you really wanted os.system, it could start with something as simple as patch below considering how os.system doesn't return data. <warning- untested, just for example> --- /usr/src/CVS/jython/Lib/javaos.py Wed Jan 31 04:38:36 2001 +++ javaos.py Mon Mar 19 18:00:37 2001 @@ -1,5 +1,6 @@ import java from java.io import File +from java.lang import Runtime import javapath path = javapath @@ -51,6 +52,10 @@ if not File(path).delete(): raise OSError(0, "couldn't delete directory", path) +def system(cmd): + if not Runtime.getRuntime().exec(cmd): + raise OSError(0, "couldn't run command: %s" % cmd) + unlink = remove def stat(path): @@ -62,5 +67,5 @@ # is zero sized or does not exist. if size == 0 and not f.exists(): raise OSError(0, 'No such file or directory', path) - mtime = f.lastModified() / 1000.0 + mtime = f.lastModified() return (0, 0, 0, 0, 0, 0, size, mtime, mtime, 0) |