Sdk: Supply an easy way to pipe shell processes or accept stdin in Process.runSync

Created on 10 May 2017  路  3Comments  路  Source: dart-lang/sdk

Create a shorthand for Process.start then process.stdin.writeln then re-sync'ing the process

area-library library-io type-enhancement

Most helpful comment

Does the following not work?

Process a = await Process.start('a');
Process b = await Process.start('b');
a.stdout.pipe(b.stdin);
String result = await UTF8.decodeStream(b.stdout);

if (await b.exitCode != 0) {
  throw something;
}

All 3 comments

As an example, instead of doing

runCheckedSync(<String>['a', '|', 'b']);

or some such, the shortest equivalent I can figure out is:

final String outputOfA = runCheckedSync(<String>['a']);
final Process processB = await Process.start('b');
processB.stdin
    ..write(outputOfA)
    ..close();

String outputOfB;
processB.stdout
    .transform<String>(UTF8.decoder)
    .listen((String output) { outputOfB = output; });
processB.stderr.drain<String>();

if (await processB.exitCode != 0) {
  throw something;
}

That was just the beginning T.T
Also have to mock everything process and streams related in mockito to test it as well

Does the following not work?

Process a = await Process.start('a');
Process b = await Process.start('b');
a.stdout.pipe(b.stdin);
String result = await UTF8.decodeStream(b.stdout);

if (await b.exitCode != 0) {
  throw something;
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Hixie picture Hixie  路  3Comments

brooth picture brooth  路  3Comments

gspencergoog picture gspencergoog  路  3Comments

jmesserly picture jmesserly  路  3Comments

xster picture xster  路  3Comments