Skip to content

Commit

Permalink
[learn_dart] process
Browse files Browse the repository at this point in the history
  • Loading branch information
chen56 committed Jun 23, 2024
1 parent c64699d commit 9ce1b2d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
32 changes: 32 additions & 0 deletions notes/learn_dart/test/dart_lang!sdk!io/process.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// ignore_for_file: avoid_print

import 'dart:convert';
import 'dart:io';
import 'package:path/path.dart' as path;

main() async {
var cmd = path.join(path.current, "test/dart_lang!sdk!io/process.sh");
await runProcess(cmd, []);
}

Future<void> runProcess(
String command,
List<String> args, {
String? cwd,
}) async {
print('\n$command ${args.join(' ')}');

var process = await Process.start(command, args, workingDirectory: cwd);

process.stdout.transform(utf8.decoder).transform(LineSplitter()).listen((line) {
print(' $line');
});
process.stderr.transform(utf8.decoder).transform(LineSplitter()).listen((line) {
print(' $line');
});

var exitCode = await process.exitCode;
if (exitCode != 0) {
throw '$command exited with $exitCode';
}
}
3 changes: 3 additions & 0 deletions notes/learn_dart/test/dart_lang!sdk!io/process.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

for i in {1..3} ; do echo $i;sleep 1; done;

0 comments on commit 9ce1b2d

Please sign in to comment.