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+.