org.python.util.PythonInterpreter.setErr()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(3.3k)|赞(0)|评价(0)|浏览(171)

本文整理了Java中org.python.util.PythonInterpreter.setErr()方法的一些代码示例,展示了PythonInterpreter.setErr()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PythonInterpreter.setErr()方法的具体详情如下:
包路径:org.python.util.PythonInterpreter
类名称:PythonInterpreter
方法名:setErr

PythonInterpreter.setErr介绍

[英]Sets a Writer to use for the standard output stream, sys.stdout. The behaviour as implemented is to output each object o by calling o.toString() and writing this as UTF-16.
[中]设置用于标准输出流的写入程序sys.stdout。实现的行为是通过调用o.toString()并将其写入UTF-16来输出每个对象o

代码示例

代码示例来源:origin: apache/flink

private static synchronized PythonInterpreter initPythonInterpreter(String[] args, String pythonPath, String scriptName) {
    if (!jythonInitialized) {
      // the java stack traces within the jython runtime aren't useful for users
      System.getProperties().put("python.options.includeJavaStackInExceptions", "false");
      PySystemState.initialize(System.getProperties(), new Properties(), args);

      pythonInterpreter = new PythonInterpreter();

      pythonInterpreter.getSystemState().path.add(0, pythonPath);

      pythonInterpreter.setErr(System.err);
      pythonInterpreter.setOut(System.out);

      pythonInterpreter.exec("import " + scriptName);
      jythonInitialized = true;
    }
    return pythonInterpreter;
  }
}

代码示例来源:origin: nodebox/nodebox

ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
interpreter.setOut(outputStream);
interpreter.setErr(errorStream);

代码示例来源:origin: org.python/jython

/**
 * Sets a {@link Writer} to use for the standard output stream, <code>sys.stdout</code>. The
 * behaviour as implemented is to output each object <code>o</code> by calling
 * <code>o.toString()</code> and writing this as UTF-16.
 *
 * @param outStream to use as the error output stream
 */
public void setErr(java.io.Writer outStream) {
  setErr(new PyFileWriter(outStream));
}

代码示例来源:origin: org.python/jython

public void setErr(java.io.OutputStream outStream) {
  setErr(new PyFile(outStream));
}

代码示例来源:origin: NGDATA/lilyproject

public JythonLineMapper(String pythonCode, String recordMapperSymbol, Writer stderrWriter) {
  interpreter = new PythonInterpreter();
  interpreter.setErr(stderrWriter);
  // TODO Should we (or can we) restrict what can be done here?
  interpreter.exec(pythonCode);
  mapperCallable = interpreter.get(recordMapperSymbol);
  if (mapperCallable == null) {
    throw new IllegalArgumentException("Symbol " + recordMapperSymbol + " cannot be found");
  }
}

代码示例来源:origin: stackoverflow.com

interpreter.setErr(outStream);
interpreter.setOut(errStream);
return interpreter;

代码示例来源:origin: org.wicketstuff/wicketstuff-console-engine

interpreter.setErr(newOut);

代码示例来源:origin: org.python/jython

private Object eval(PyCode code, ScriptContext context) throws ScriptException {
  try {
    interp.setIn(context.getReader());
    interp.setOut(context.getWriter());
    interp.setErr(context.getErrorWriter());
    interp.setLocals(new PyScriptEngineScope(this, context));
    return interp.eval(code).__tojava__(Object.class);
  } catch (PyException pye) {
    throw scriptException(pye);
  }
}

代码示例来源:origin: org.jvnet.hudson.plugins/jython

public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener)  throws IOException, InterruptedException {
    PySystemState sys = new PySystemState();
    sys.setCurrentWorkingDir(build.getWorkspace().getRemote());
    PythonInterpreter interp = new PythonInterpreter(null, sys);

    interp.setOut(listener.getLogger());
    interp.setErr(listener.getLogger());
    interp.exec(this.getCommand());
    interp.cleanup();

    build.setResult(Result.SUCCESS);
    return true;
  }
}

相关文章