1 3 5 22 23 package edu.neu.ccs.jmk.shell; 24 25 import org.python.util.PythonInterpreter; 26 import org.python.core.PyException; 27 import edu.neu.ccs.jmk.Operator; 28 import edu.neu.ccs.jmk.CommandFailedException; 29 30 41 public class JPython 42 implements Operator 43 { 44 public String getName() { 45 return "JPython"; 46 } 47 48 55 public void exec(String [] args, java.io.PrintWriter out) 56 throws CommandFailedException 57 { 58 if (args.length == 0) 59 throw new CommandFailedException("No args to " + getName()); 60 StringBuffer sb = new StringBuffer (args[0]); 61 for (int i = 1; i < args.length; i++) 62 sb.append(args[i]); 63 PythonInterpreter pi = new PythonInterpreter(); 64 try { 65 pi.exec(sb.toString()); 66 } 67 catch (PyException pex) { 68 out.println(pex); 69 throw new CommandFailedException(getName() + " threw an exception"); 70 } 71 } 72 } 73 | Popular Tags |