Class ProcessSupport
java.lang.Object
de.iip_ecosphere.platform.services.environment.ProcessSupport
Process execution support functions. Process scripts or binaries shall be packaged using a Maven assembly
descriptor into a ZIP file in the "root" of the Jar/Service artifact (fallback for testing can be defined,
e.g., src/main/python/...). Here, the name is free, but shall not collide with the default process artifacts
of generated services.
- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classHolds the script context. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Consumer<ProcessBuilder> A simple default customizer always requesting to inherit the process IO (standard in/out/err). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcallPython(ProcessSupport.ScriptOwner owner, String script, Consumer<String> cmdResult, String... args) Call python scripts, waiting for and killing finally.static intcallPythonWaitForAndKill(File dir, String script, Consumer<String> cmdResult, String resultFile, Consumer<ProcessBuilder> cust, String... args) Call python, wait for ending and kill it if needed.static ProcesscreatePythonProcess(File dir, String script, Consumer<ProcessBuilder> procCustomizer, String... args) Creates and starts a Python process.static intWait for a (scripted) process until it is really dead.
-
Field Details
-
INHERIT_IO
A simple default customizer always requesting to inherit the process IO (standard in/out/err). May particularly be helpful for debugging.
-
-
Constructor Details
-
ProcessSupport
public ProcessSupport()
-
-
Method Details
-
callPython
public static void callPython(ProcessSupport.ScriptOwner owner, String script, Consumer<String> cmdResult, String... args) Call python scripts, waiting for and killing finally. Scripts shall be located in a Maven packaged ZIP represented byowner(including unpacking state).- Parameters:
owner- the script owner and data instancescript- the script file name to execute in the context ofownercmdResult- a consumer for the result, may be null for noneargs- the process arguments for the script including python arguments (first), script and script arguments
-
createPythonProcess
public static Process createPythonProcess(File dir, String script, Consumer<ProcessBuilder> procCustomizer, String... args) throws IOException Creates and starts a Python process.- Parameters:
dir- the home dir where to find the script/run it withinscript- the script to executeprocCustomizer- allows to customize the internal process builder, may be null for noneargs- the process arguments for the script including python arguments (first), script and script arguments- Returns:
- the created process
- Throws:
IOException- if process creation fails
-
waitForAndKill
public static int waitForAndKill(Process proc, String script, Consumer<String> cmdResult, String resultFile) Wait for a (scripted) process until it is really dead.- Parameters:
proc- the process to wait forscript- the script name for loggingcmdResult- a consumer for the result, may be null for noneresultFile- file to read result from, e.g., short lived processes, ifnulluse standard in- Returns:
- the process status,
-1if the process was not executed - See Also:
-
callPythonWaitForAndKill
public static int callPythonWaitForAndKill(File dir, String script, Consumer<String> cmdResult, String resultFile, Consumer<ProcessBuilder> cust, String... args) Call python, wait for ending and kill it if needed. Catch all exceptions.- Parameters:
dir- the home dir where to find the script/run it withinscript- the script to executecmdResult- a consumer for the result, may be null for noneresultFile- file to read result from, e.g., short lived processes, ifnulluse standard incust- optional process customizer, may be null for noneargs- the process arguments for the script including python arguments (first), script and script arguments- Returns:
- the process status,
-1if the process was not executed - See Also:
-