Run external command in dart

Viewed 414

Is it possible to run an external command in Dart? I need to run the external command plutil, but everything I google gives me results to run Dart code from the command line, so I have not been able to find a solution. Thanks!

1 Answers

Example of Run external command in dart:

import 'dart:io';

void main(List<String> args) async {
  var executable = 'ls';
  if (Platform.isWindows) {
    executable = 'dir';
  }

  final arguments = <String>[];
  print('List Files and Directories');
  print('============');
  final process = await Process.start(executable, arguments, runInShell: true);
  await stdout.addStream(process.stdout);
  await stderr.addStream(process.stderr);
  final exitCode = await process.exitCode;
  print('============');
  print('Exit code: $exitCode');
}
Related