Package com.dtolabs.rundeck.core.utils
Class ScriptExecUtil
- java.lang.Object
-
- com.dtolabs.rundeck.core.utils.ScriptExecUtil
-
public class ScriptExecUtil extends java.lang.ObjectProvides methods for running scripts/commands.
-
-
Constructor Summary
Constructors Constructor Description ScriptExecUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ExecArgListcreateScriptArgList(java.lang.String filepath, java.lang.String scriptargs, java.lang.String[] scriptargsarr, java.lang.String scriptinterpreter, boolean interpreterargsquoted)Generate argument array for a script file invocationstatic java.lang.String[]createScriptArgs(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> localDataContext, INodeEntry node, java.lang.String scriptargs, java.lang.String[] scriptargsarr, java.lang.String scriptinterpreter, boolean interpreterargsquoted)Generate argument array for a script file invocationstatic java.lang.String[]createScriptArgs(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> localDataContext, INodeEntry node, java.lang.String scriptargs, java.lang.String[] scriptargsarr, java.lang.String scriptinterpreter, boolean interpreterargsquoted, java.lang.String filepath)Generate argument array for a script file invocationstatic java.lang.String[]createScriptArgs(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> localDataContext, java.lang.String scriptargs, java.lang.String[] scriptargsarr, java.lang.String scriptinterpreter, boolean interpreterargsquoted, java.lang.String filepath)Generate argument array for a script file invocationstatic ScriptExecHelperhelper()static voidkillProcessHandle(java.lang.ProcessHandle handle)static voidkillProcessHandleDescend(java.lang.ProcessHandle handle)static java.util.Map<java.lang.String,java.lang.String>loadLocalEnvironment()static intrunLocalCommand(java.lang.String[] command, java.util.Map<java.lang.String,java.lang.String> envMap, java.io.File workingdir, java.io.OutputStream outputStream, java.io.OutputStream errorStream)Run a command with environment variables in a working dir, and copy the streamsstatic intrunLocalCommand(java.lang.String[] command, java.util.Map<java.lang.String,java.lang.String> envMap, java.io.File workingdir, java.io.OutputStream outputStream, java.io.OutputStream errorStream, boolean clearEnv, java.util.function.Consumer<java.lang.ProcessHandle> killHandler)Run a command with environment variables in a working dir, and copy the streamsstatic intrunLocalCommand(java.lang.String[] command, java.util.Map<java.lang.String,java.lang.String> envMap, java.io.File workingdir, java.io.OutputStream outputStream, java.io.OutputStream errorStream, boolean clearEnv, java.util.function.Consumer<java.lang.ProcessHandle> killHandler, java.io.InputStream inputStream)Run a command with environment variables in a working dir, and copy the streamsstatic intrunLocalCommand(java.lang.String osFamily, ExecArgList execArgList, java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> dataContext, java.io.File workingdir, java.io.OutputStream outputStream, java.io.OutputStream errorStream)Run a command with environment variables in a working dir, and copy the streams
-
-
-
Method Detail
-
helper
public static ScriptExecHelper helper()
- Returns:
- instance of the helper interface
-
runLocalCommand
public static int runLocalCommand(java.lang.String osFamily, ExecArgList execArgList, java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> dataContext, java.io.File workingdir, java.io.OutputStream outputStream, java.io.OutputStream errorStream) throws java.io.IOException, java.lang.InterruptedExceptionRun a command with environment variables in a working dir, and copy the streams- Parameters:
osFamily- local node os familyexecArgList- the ExecArgList to runworkingdir- optional working dir location (or null)outputStream- stream for stdouterrorStream- stream for stderrdataContext- data- Returns:
- the exit code of the command
- Throws:
java.io.IOException- if any IO exception occursjava.lang.InterruptedException- if interrupted while waiting for the command to finish
-
runLocalCommand
public static int runLocalCommand(java.lang.String[] command, java.util.Map<java.lang.String,java.lang.String> envMap, java.io.File workingdir, java.io.OutputStream outputStream, java.io.OutputStream errorStream) throws java.io.IOException, java.lang.InterruptedExceptionRun a command with environment variables in a working dir, and copy the streams- Parameters:
command- the command array to runenvMap- the environment variables to pass inworkingdir- optional working dir location (or null)outputStream- stream for stdouterrorStream- stream for stderr- Returns:
- the exit code of the command
- Throws:
java.io.IOException- if any IO exception occursjava.lang.InterruptedException- if interrupted while waiting for the command to finish
-
runLocalCommand
public static int runLocalCommand(java.lang.String[] command, java.util.Map<java.lang.String,java.lang.String> envMap, java.io.File workingdir, java.io.OutputStream outputStream, java.io.OutputStream errorStream, boolean clearEnv, java.util.function.Consumer<java.lang.ProcessHandle> killHandler) throws java.io.IOException, java.lang.InterruptedExceptionRun a command with environment variables in a working dir, and copy the streams- Parameters:
command- the command array to runenvMap- the environment variables to pass inworkingdir- optional working dir location (or null)outputStream- stream for stdouterrorStream- stream for stderr- Returns:
- the exit code of the command
- Throws:
java.io.IOException- if any IO exception occursjava.lang.InterruptedException- if interrupted while waiting for the command to finish
-
runLocalCommand
public static int runLocalCommand(java.lang.String[] command, java.util.Map<java.lang.String,java.lang.String> envMap, java.io.File workingdir, java.io.OutputStream outputStream, java.io.OutputStream errorStream, boolean clearEnv, java.util.function.Consumer<java.lang.ProcessHandle> killHandler, java.io.InputStream inputStream) throws java.io.IOException, java.lang.InterruptedExceptionRun a command with environment variables in a working dir, and copy the streams- Parameters:
command- the command array to runenvMap- the environment variables to pass inworkingdir- optional working dir location (or null)outputStream- stream for stdouterrorStream- stream for stderr- Returns:
- the exit code of the command
- Throws:
java.io.IOException- if any IO exception occursjava.lang.InterruptedException- if interrupted while waiting for the command to finish
-
killProcessHandleDescend
public static void killProcessHandleDescend(java.lang.ProcessHandle handle)
-
killProcessHandle
public static void killProcessHandle(java.lang.ProcessHandle handle)
-
loadLocalEnvironment
public static java.util.Map<java.lang.String,java.lang.String> loadLocalEnvironment()
- Returns:
- local environment variables
-
createScriptArgs
public static java.lang.String[] createScriptArgs(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> localDataContext, java.lang.String scriptargs, java.lang.String[] scriptargsarr, java.lang.String scriptinterpreter, boolean interpreterargsquoted, java.lang.String filepath)Generate argument array for a script file invocation- Parameters:
localDataContext- data context properties to expand among the argsscriptargs- arguments to the script filescriptargsarr- arguments to the script file as an arrayscriptinterpreter- interpreter invocation for the file, or null to invoke it directlyinterpreterargsquoted- if true, pass the script file and args as a single argument to the interpreterfilepath- remote filepath for the script- Returns:
- args
-
createScriptArgList
public static ExecArgList createScriptArgList(java.lang.String filepath, java.lang.String scriptargs, java.lang.String[] scriptargsarr, java.lang.String scriptinterpreter, boolean interpreterargsquoted)
Generate argument array for a script file invocation- Parameters:
filepath- remote filepath for the scriptscriptargs- arguments to the script filescriptargsarr- arguments to the script file as an arrayscriptinterpreter- interpreter invocation for the file, or null to invoke it directly, can include ${scriptfile}interpreterargsquoted- if true, pass the script file and args as a single argument to the interpreter- Returns:
- arg list
-
createScriptArgs
public static java.lang.String[] createScriptArgs(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> localDataContext, INodeEntry node, java.lang.String scriptargs, java.lang.String[] scriptargsarr, java.lang.String scriptinterpreter, boolean interpreterargsquoted)Generate argument array for a script file invocation- Parameters:
localDataContext- data context properties to expand among the argsnode- node to use for os-type argument quoting.scriptargs- arguments to the script filescriptargsarr- arguments to the script file as an arrayscriptinterpreter- interpreter invocation for the file, or null to invoke it directlyinterpreterargsquoted- if true, pass the script file and args as a single argument to the interpreter- Returns:
- args
-
createScriptArgs
public static java.lang.String[] createScriptArgs(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> localDataContext, INodeEntry node, java.lang.String scriptargs, java.lang.String[] scriptargsarr, java.lang.String scriptinterpreter, boolean interpreterargsquoted, java.lang.String filepath)Generate argument array for a script file invocation- Parameters:
localDataContext- data context properties to expand among the argsnode- node to use for os-type argument quoting.scriptargs- arguments to the script filescriptargsarr- arguments to the script file as an arrayscriptinterpreter- interpreter invocation for the file, or null to invoke it directlyinterpreterargsquoted- if true, pass the script file and args as a single argument to the interpreterfilepath- remote filepath for the script- Returns:
- args
-
-