start function
Allows you to execute a cli commandLine
.
DCli performs Glob expansion on command arguments. See run for details.
Runs the given commandLine
which may contain a command and
arguments to pass to the command.
You may pass in a progress
which allows you to process
output as it is generated. If you pass in a progress
the same
progress
is returned from the start method.
If you don't passing in a progress
then a default progress
is created
which suppresses output from both stdout and stderr.
and returned from the method, however as the run method is synchronous (like all DCli commands) you won't be able to process the output until the command completes.
The returned progress
gives you access to the exit code of the called
application, if and only if you set nothrow
to true.
if nothrow
is false (the default for most methods that use run) then
a non-zero exit code will result in an exception being thrown.
The privileged
argument attempts to escalate the priviledge that
the command is run
at.
If the script is already running in a priviledge environment this
switch will have no
affect.
Running a command with the privileged
switch may cause the OS to
prompt the user
for a password.
For Linux passing the privileged
argument will cause the command
to be prefix
vai the sudo
command.
Current privileged
is only supported under Linux.
if runInShell
is set to true (default is false) then command will
be run in a shell (e.g. bash).
If you pass detached
= true then the process is spawned but we don't wait
for it to complete nor is any io available.
Implementation
Progress start(
String commandLine, {
Progress? progress,
bool runInShell = false,
bool detached = false,
bool terminal = false,
bool nothrow = false,
bool privileged = false,
String? workingDirectory,
bool extensionSearch = true,
}) {
workingDirectory ??= pwd;
final runnable = RunnableProcess.fromCommandLine(
commandLine,
workingDirectory: workingDirectory,
);
return runnable.run(
progress: progress,
runInShell: runInShell,
detached: detached,
terminal: terminal,
privileged: privileged,
nothrow: nothrow,
extensionSearch: extensionSearch,
);
}