startFromArgs function
Allows you to execute a command by passing a command
and a list of args in args
.
The startFromArgs method provides additional controls (compared to the run method) over how the commmand is executed.
DCli will do glob expansion (e.g. expand *.txt to a list of txt files) on each passed argument (for Linux and MacOS). You can stop glob expansion by adding a set of single or double quotes around each argument.
DCli will remove the extra quotes and NOT perform glob expansion.
e.g. '''"dontexpand.*"'''
results in dontexpand.*
By default startFromArgs will output both stdout and stderr to the console.
Pass in a progress
to capture or suppress stdout and stderr.
The privileged
argument attempts to escalate the priviledge that
the command is run with.
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/MacOS passing the privileged
argument will cause the command
to be prefix vai the sudo
command unless the script is already
running as a privileged process.
Currently privileged
is not supported under Windows see withPrivileged as
an alternative.
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 startFromArgs(
String command,
List<String> args, {
Progress? progress,
bool runInShell = false,
bool detached = false,
bool terminal = false,
bool privileged = false,
bool nothrow = false,
String? workingDirectory,
bool extensionSearch = true,
}) {
progress ??= Progress.print();
workingDirectory ??= pwd;
final runnable = RunnableProcess.fromCommandArgs(
command,
args,
workingDirectory: workingDirectory,
);
return runnable.run(
progress: progress,
runInShell: runInShell,
detached: detached,
terminal: terminal,
privileged: privileged,
nothrow: nothrow,
extensionSearch: extensionSearch,
);
}