writeWindowsBatchScript method

  1. @protected
  2. @nonVirtual
Future<void> writeWindowsBatchScript({
  1. required File file,
  2. required String contents,
  3. bool changeCodePage = true,
})

Implementation

@protected
@nonVirtual
Future<void> writeWindowsBatchScript({
  required io.File file,
  required String contents,
  bool changeCodePage = true,
}) async {
  if (!io.Platform.isWindows)
    throw UnsupportedError(
      "This method can only be used on Windows systems.",
    );

  if (changeCodePage) {
    contents = """
@echo off
REM Change code page
chcp $windowsCodePage > nul

$contents
""";
  }

  await file.writeAsString(
    contents,
    mode: io.FileMode.writeOnly,
    flush: true,
    encoding: io.systemEncoding,
  );
}