writeWindowsBatchScriptSync method

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

Implementation

@protected
@nonVirtual
void writeWindowsBatchScriptSync({
  required io.File file,
  required String contents,
  bool changeCodePage = true,
}) {
  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
""";
  }

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