write function

IOSink write(
  1. String path
)

A shorthand for opening a sink that writes to the file at path.

With Script.operator >, this can be used to write the output of a script to a file:

import 'dart:io';

import 'package:cli_script/cli_script.dart';

void main() {
  wrapMain(() {
    Script.capture((_) async {
      await for (var file in lines("find . -type f -maxdepth 1")) {
        var contents = await output("cat", args: [file]);
        if (contents.contains("needle")) print(file);
      }
    }) > write("needles.txt");
  });
}

Implementation

IOSink write(String path) => File(path).openWrite();