Running a subprocess with Dart and reading its output

Starting a foreign program, and reading its standard output stream is useful, and here is an example of listing the root directory.
void main() {
  Process p = new Process('/bin/ls', ['/']);
  p.start();
  StringInputStream stdoutStream = new StringInputStream(p.stdout);
  print(stdoutStream.read());
  p.close();
}
Notes:

  • Argument list does not include the executable name like it usually does
  • Use a StringInputStream to read an InputStream as a String
  • Close the process or the script will hang forever
Comments on Google+.


Popular posts from this blog

PyGTK, Py2exe, and Inno setup for single-file Windows installers

ESP-IDF for Arduino Users, Tutorials Part 2: Delay

How to install IronPython2 with Mono on Ubuntu