Functions
func execute(String, Array<String>, ?Path, ?Map<String, String>, ProcessRedirect, ProcessRedirect,ProcessRedirect, ?Duration)
public func execute(command: String,
arguments: Array<String>,
workingDirectory!: ?Path = None,
environment!: ?Map<String, String> = None,
stdIn!: ProcessRedirect = Inherit,
stdOut!: ProcessRedirect = Inherit,
stdErr!: ProcessRedirect = Inherit,
timeout!: ?Duration = None): Int64
Description: Creates and runs a subprocess based on input parameters, waits until the subprocess is complete, and returns the exit status of the subprocess.
NOTE
- On
Windows, if the executable file of a subprocess is deleted immediately after the subprocess is executed, the deletion may fail and an exception is thrown. The exception information isAccess is denied. If this problem occurs, the file can be deleted again after a short delay. For details, see the example.
Parameters:
- command: String: specifies the subprocess command. The value of
commandcannot contain null characters. - arguments: Array<String>: specifies the subprocess parameters. The strings in the
argumentsarray cannot contain null characters. - workingDirectory!: ?Path: specifies the working path of the subprocess. This parameter is optional and inherits the working path of the current process by default. The path must exist and cannot be empty or contain null characters.
- environment!: ?Map<String, String>: specifies the environment variables of the subprocess. This parameter is optional and inherits the environment variables of the current process by default. The
keystring cannot contain null characters or equal signs (=), and thevaluestring cannot contain null characters. - stdIn!: ProcessRedirect: specifies the standard input for subprocess redirection. This parameter is optional and inherits the standard input of the current process by default.
- stdOut!: ProcessRedirect: specifies the standard output for subprocess redirection. This parameter is optional and inherits the standard output of the current process by default.
- stdErr!: ProcessRedirect: specifies the standard error for subprocess redirection. This parameter is optional and inherits the standard error of the current process by default.
- timeout!: ?Duration: specifies the timeout interval for waiting for the subprocess to complete. This parameter is optional and set to
0or a negative value by default, indicating that no timeout is set.
Returns:
- Int64: The exit status of the subprocess is returned. If the subprocess exits normally, the exit code of the subprocess is returned. If the subprocess is killed by a signal, the number of the signal that causes the subprocess to terminate is returned.
Throws:
-
- If the value of
commandcontains null characters, - the string in the
argumentsarray contains null characters, workingDirectorydoes not exist, or is an empty path, or contains null characters,- the
keystring in theenvironmenttable contains null characters or equal signs (=), - the
valuestring in theenvironmenttable contains null characters, - or
stdIn,stdOut, orstdErris input through a file, and the input file has been closed or deleted, this exception is thrown.
- If the value of
-
ProcessException: If memory allocation fails, the command specified by
commanddoes not exist, or the waiting times out, this exception is thrown.
func executeWithOutput(String, Array<String>, ?Path, ?Map<String, String>, ProcessRedirect, ProcessRedirect, ProcessRedirect)
public func executeWithOutput(command: String,
arguments: Array<String>,
workingDirectory!: ?Path = None,
environment!: ?Map<String, String> = None,
stdIn!: ProcessRedirect = Inherit,
stdOut!: ProcessRedirect = Pipe,
stdErr!: ProcessRedirect = Pipe): (Int64, Array<Byte>, Array<Byte>)
Description: Creates and runs a subprocess based on input parameters, waits until the subprocess is complete, and returns the exit status, standard output, and standard error of the subprocess. This function is not applicable to the scenario where the output stream and error stream contain a large amount of output. It is recommended that the standard stream attributes provided in SubProcess and the wait function be used together to process the output stream and error stream.
Parameters:
- command: String: specifies the subprocess command. The value of
commandcannot contain null characters. - arguments: Array<String>: specifies the subprocess parameters. The strings in the
argumentsarray cannot contain null characters. - workingDirectory!: ?Path: specifies the working path of the subprocess. This parameter is optional and inherits the working path of the current process by default. The path must exist and cannot be empty or contain null characters.
- environment!: ?Map<String, String>: specifies the environment variables of the subprocess. This parameter is optional and inherits the environment variables of the current process by default. The
keystring cannot contain null characters or equal signs (=), and thevaluestring cannot contain null characters. - stdIn!: ProcessRedirect: specifies the standard input for subprocess redirection. This parameter is optional and inherits the standard input of the current process by default.
- stdOut!: ProcessRedirect: specifies the standard output for subprocess redirection. This parameter is optional and inherits the standard output of the current process by default.
- stdErr!: ProcessRedirect: specifies the standard error for subprocess redirection. This parameter is optional and inherits the standard error of the current process by default.
Returns:
- (Int64, Array<Byte>, Array<Byte>): The subprocess execution result is returned, including the subprocess exit status (if the subprocess exits normally, the exit code of the subprocess is returned; if the subprocess is killed by a signal, the number of the signal that causes the subprocess to terminate is returned), standard process output result, and process error result.
Throws:
- IllegalArgumentException
- If the value of
commandcontains null characters, - the string in the
argumentsarray contains null characters, workingDirectorydoes not exist, or is an empty path, or contains null characters,- the
keystring in theenvironmenttable contains null characters or equal signs (=), - the
valuestring in theenvironmenttable contains null characters, - or
stdIn,stdOut, orstdErris input through a file, and the input file has been closed or deleted, this exception is thrown.
- If the value of
- ProcessException
- If memory allocation fails,
- the command specified by
commanddoes not exist, - the subprocess does not exist,
- or an exception occurs when the standard stream is read, this exception is thrown.
func findProcess(Int64)
public func findProcess(pid: Int64): Process
Description: Binds a process instance based on the input process id.
Parameters:
- pid: Int64: process
id
Returns:
- Process: The process instance corresponding to the process
idis returned.
Throws:
- IllegalArgumentException: If the input process
idis greater than the maximum value of Int32 or less than0, this exception is thrown. - ProcessException: If memory allocation fails or the process specified by
piddoes not exist, this exception is thrown.
func launch(String, Array<String>, ?Path, ?Map<String, String>, ProcessRedirect, ProcessRedirect, ProcessRedirect)
public func launch(command: String,
arguments: Array<String>,
workingDirectory!: ?Path = None,
environment!: ?Map<String, String> = None,
stdIn!: ProcessRedirect = Inherit,
stdOut!: ProcessRedirect = Inherit,
stdErr!: ProcessRedirect = Inherit): SubProcess
Description: Creates and runs a subprocess based on input parameters and returns a subprocess instance. After this function is called to create a subprocess, the wait or waitOutput function needs to be called. Otherwise, the resources of the zombie process formed after the subprocess ends will not be recycled.
Parameters:
- command: String: specifies the subprocess command. The value of
commandcannot contain null characters. - arguments: Array<String>: specifies the subprocess parameters. The strings in the
argumentsarray cannot contain null characters. - workingDirectory!: ?Path: specifies the working path of the subprocess. This parameter is optional and inherits the working path of the current process by default. The path must exist and cannot be empty or contain null characters.
- environment!: ?Map<String, String>: specifies the environment variables of the subprocess. This parameter is optional and inherits the environment variables of the current process by default. The
keystring cannot contain null characters or equal signs (=), and thevaluestring cannot contain null characters. - stdIn!: ProcessRedirect: specifies the standard input for subprocess redirection. This parameter is optional and inherits the standard input of the current process by default.
- stdOut!: ProcessRedirect: specifies the standard output for subprocess redirection. This parameter is optional and inherits the standard output of the current process by default.
- stdErr!: ProcessRedirect: specifies the standard error for subprocess redirection. This parameter is optional and inherits the standard error of the current process by default.
Returns:
- SubProcess: A subprocess instance is returned.
Throws:
- IllegalArgumentException
- If the value of
commandcontains null characters, - the string in the
argumentsarray contains null characters, workingDirectorydoes not exist, or is an empty path, or contains null characters,- the
keystring in theenvironmenttable contains null characters or equal signs (=), - the
valuestring in theenvironmenttable contains null characters, - or
stdIn,stdOut, orstdErris input through a file, and the input file has been closed or deleted, this exception is thrown.
- If the value of
- ProcessException: If memory allocation fails or the command specified by
commanddoes not exist, this exception is thrown.