createTempScript static method

Future<String> createTempScript(
  1. String? command
)

Under POSIX-compliant OS, does nothing and returns an empty string.
Under Windows, creates a temporary folder (non-blocking) and writes command to an output file.
This file should be executed and deleted with the containing folder

Implementation

static Future<String> createTempScript(String? command) async {
  if ((command == null) || command.isEmpty) {
    return '';
  }

  final dir = await createTempDir();
  final path = p.join(dir.path, _getScriptName());
  final file = File(path);

  try {
    final script = _toScript(command);
    await file.writeAsString(script, flush: true);
    return path;
  } on Exception catch (_) {
    await deleteTempScript(path);
    rethrow;
  } on Error catch (_) {
    await deleteTempScript(path);
    rethrow;
  }
}