RunCmdFromPath procedure
Executes a command using the specified parameters and process options.
Declaration
procedure RunCmdFromPath(const ProgramFilename: string;
const CmdLineParameters: string;
ProcessOpts: TProcessOptions=[poWaitOnExit])Arguments
ProgramFilename | Path and name for the program executed in the routine. |
CmdLineParameters | Command line parameters for the program. |
ProcessOpts | Set of process options enabled during execution of the command. |
Description
RunCmdFromPath is used to execute a command which can be found in
the current
PATH environment. For example, the following locates
and executes the
/bin/ls -l /home command:
RunCmdFromPath('ls', '-l /home');
An exception is raised if the program file cannot be located, or cannot be executed.
RunCmdFromPath creates and configures a TProcessUTF8 instance
which is used to execute the program file.
ProgramFilename contains the qualified executable file name for the
process. If the argument contains a
Space (
' '), it is
surrounded by
Quotation Mark (
") characters before it is
assigned to the class instance.
CmdLineParameters contains optional parameters values for the
executable file. It is assumed that parameter values with embedded spaces are
already quoted when passed to the routine. CmdLineParameters is included in
the class instance when the value is not an empty string (
'').
ProcessOpts contains the set of
TProcessOption values
enabled during execution of the process. The default value for the parameter
is [poWaitOnExit], and causes Execute to wait for completion of the process
before setting the exit status and exit code.
RunCmdFromPath calls the Execute method in the TProcessUTF8
instance to execute the specified program file name with the specified
parameter values and process options. The process instance is configured so
that it does not inherit handles for StdIn, StdOut, and StdErr during
process execution.
Modified in LazUtils version 2.3.0 to wait for process exit during execution. Modified in LazUtils version 5.0 to accept process options as a parameter.
Errors
- EFOpenError
- Raised with the message in lrsProgramFileNotFound or lrsCanNotExecute.
See also
An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
