fromEnvironment static method
Future<ProcessInterface>
fromEnvironment(
- String programName,
- List<
String> arguments, { - ProcessInterfaceOptions options = const ProcessInterfaceOptions(),
- ProcessInterfaceOutputCallback? onStdout,
- ProcessInterfaceOutputCallback? onStderr,
Creates a ProcessInterface by searching for programName in the system PATH.
programName: The name of the executable to search for.arguments: Command line arguments for the invocation.options: Options for the process invocation.onStdout&onStderr: Optional callbacks to listen to output.
Throws ApplicationNotFoundException if the program isn't found in PATH.
Implementation
static Future<ProcessInterface> fromEnvironment(
String programName, List<String> arguments,
{final ProcessInterfaceOptions options = const ProcessInterfaceOptions(),
final ProcessInterfaceOutputCallback? onStdout,
final ProcessInterfaceOutputCallback? onStderr}) {
final List<String> pathEntries =
Platform.environment["PATH"]?.split(Platform.isWindows ? ";" : ":") ??
[];
final File? file = pathEntries
.map((pathEntry) => File(
path.join(
pathEntry,
programName + (Platform.isWindows ? ".exe" : ""),
),
))
.firstWhereOrNull((file) => file.existsSync());
if (file == null) {
throw ApplicationNotFoundException(programName);
}
return fromFilepath(file.path, arguments,
options: options, onStdout: onStdout, onStderr: onStderr);
}