Add optional prefix to runCommandAndStreamOutput for logs commands.

This commit is contained in:
Ian Fischer 2015-09-29 14:15:29 -07:00
parent 5e11889160
commit a6635489f5
2 changed files with 5 additions and 4 deletions

View file

@ -334,7 +334,7 @@ class AndroidDevice extends _Device {
'-s',
'sky',
'chromium',
]);
], prefix: 'ANDROID: ');
}
@override

View file

@ -14,15 +14,16 @@ final Logger _logging = new Logger('sky_tools.process');
/// This runs the command and streams stdout/stderr from the child process to
/// this process' stdout/stderr.
Future<int> runCommandAndStreamOutput(List<String> cmd) async {
Future<int> runCommandAndStreamOutput(List<String> cmd,
{String prefix: ''}) async {
_logging.info(cmd.join(' '));
Process proc =
await Process.start(cmd[0], cmd.getRange(1, cmd.length).toList());
proc.stdout.transform(UTF8.decoder).listen((data) {
stdout.write(data);
stdout.write('$prefix${data.trimRight().split('\n').join('\n$prefix')}\n');
});
proc.stderr.transform(UTF8.decoder).listen((data) {
stderr.write(data);
stderr.write('$prefix${data.trimRight().split('\n').join('\n$prefix')}\n');
});
return proc.exitCode;
}