execCommand static method

Future<String> execCommand(
  1. String command, {
  2. dynamic type = ScriptRunType.shell,
  3. Shell? shell,
  4. String? path,
})

Implementation

static Future<String> execCommand(
  final String command, {
  final type = ScriptRunType.shell,
  Shell? shell,
  String? path,
}) async {
  try {
    if (type == ScriptRunType.terminal) {
      final process = await Process.run(command, [], workingDirectory: path);
      debugPrint("Process: $process");
      return process.stdout;
    } else {
      shell ??= Shell();
      final String response =
          (await shell.run(path != null ? "cd $path; $command" : command))
              .outText;
      log("ScriptRunner", "Response: $response");
      return response;
    }
  } on ProcessException {
    // Toast.show("Script Run failed", message: ex.message.toString());
    return "";
  }
}