You can execute the C language version of Python through the cpython library of http://bytedeco.org/.
As an action, implement the run() method, and execute the code written in the model code attribute in the run() method.
The run method code is as follows:
public static Object run(ActionContext actionContext) throws IOException {
Thing self = actionContext.getObject("self");
Pointer program = Py_DecodeLocale(CPythonAction.class.getSimpleName(), null);
if (program == null) {
Executor.warn(TAG, "Fatal error: cannot decode class name");
}
try {
Py_SetProgramName(program); /* optional but recommended */
Py_Initialize(cachePackages());
String code = self.getStringBlankAsNull("code");
if (code != null) {
PyRun_SimpleString(code);
}
return Py_FinalizeEx();
}finally {
PyMem_RawFree(program);
}
}
<?xml version='1.0' encoding='utf-8'?>
<CPythonAction name="CPythonAction" descriptors="xworker.cpython.CPythonAction">
<code><![CDATA[from time import time,ctime
print('Today is', ctime(time()))]]></code>
</CPythonAction>
Copyright © 2007-2019 XWorker.org 版权所有 沪ICP备08000575号