Skip to content

Instantly share code, notes, and snippets.

@bsutton
Created January 15, 2020 07:20
Show Gist options
  • Select an option

  • Save bsutton/3ad46c7e28c80f6735a9ee350091d509 to your computer and use it in GitHub Desktop.

Select an option

Save bsutton/3ad46c7e28c80f6735a9ee350091d509 to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'dart:convert';
import 'dart:io';
void main() async {
var ls = await start('ls');
var head = await start('head');
var headStdout = head.stdout;
ls.stdout
.transform(utf8.decoder)
.transform(const LineSplitter())
.map((line) {
print(line);
return '1: line';
})
.transform(utf8.encoder)
.listen((line) => head.stdin.add(line), onDone: () {
});
headStdout
.transform(utf8.decoder)
.transform(const LineSplitter())
.listen((line) => print(line), onDone: () {
head.stdin.close();
});
}
Future<Process> start(String command) async
{
var process = Process.start(
command,
[],
);
return process;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment