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

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

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

PythonInterpreter.setOut介绍

[英]Sets a java.io.OutputStream to use for the standard output stream.
[中]设置一个java。伊奥。用于标准输出流的OutputStream。

代码示例

代码示例来源: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 outputStream = new ByteArrayOutputStream();
ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
interpreter.setOut(outputStream);
interpreter.setErr(errorStream);

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

public void setOut(Writer out) {
  interpreter.setOut(out);
}

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

/**
 * Sets a {@link java.io.OutputStream} to use for the standard output stream.
 *
 * @param outStream OutputStream to use as output stream
 */
public void setOut(java.io.OutputStream outStream) {
  setOut(new PyFile(outStream));
}

代码示例来源: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 output stream
 */
public void setOut(java.io.Writer outStream) {
  setOut(new PyFileWriter(outStream));
}

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

interpreter.setOut(errStream);
  return interpreter;
}}

代码示例来源:origin: org.nuiton.jrst/jrst

interp.setOut(out);

代码示例来源:origin: org.nuiton.jrst/jrst

interp.setOut(out);

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

interpreter.setOut(newOut);
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;
  }
}

相关文章