Created
January 15, 2020 07:20
-
-
Save bsutton/3ad46c7e28c80f6735a9ee350091d509 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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