| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Information about the environment in which the current program is running. | 8 * Information about the environment in which the current program is running. |
| 9 * | 9 * |
| 10 * Platform provides information such as the operating system, | 10 * Platform provides information such as the operating system, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 * variables in a [Map] that contains key-value pairs of strings. The Map is | 32 * variables in a [Map] that contains key-value pairs of strings. The Map is |
| 33 * unmodifiable. This sample shows how to get the value of the `PATH` | 33 * unmodifiable. This sample shows how to get the value of the `PATH` |
| 34 * environment variable. | 34 * environment variable. |
| 35 * | 35 * |
| 36 * import 'dart:io' show Platform; | 36 * import 'dart:io' show Platform; |
| 37 * | 37 * |
| 38 * void main() { | 38 * void main() { |
| 39 * Map<String, String> envVars = Platform.environment; | 39 * Map<String, String> envVars = Platform.environment; |
| 40 * print(envVars['PATH']); | 40 * print(envVars['PATH']); |
| 41 * } | 41 * } |
| 42 * | 42 * |
| 43 * ## Determine the OS | 43 * ## Determine the OS |
| 44 * | 44 * |
| 45 * You can get the name of the operating system as a string with the | 45 * You can get the name of the operating system as a string with the |
| 46 * [operatingSystem] getter. You can also use one of the static boolean | 46 * [operatingSystem] getter. You can also use one of the static boolean |
| 47 * getters: [isMacOS], [isLinux], and [isWindows]. | 47 * getters: [isMacOS], [isLinux], and [isWindows]. |
| 48 * | 48 * |
| 49 * import 'dart:io' show Platform, stdout; | 49 * import 'dart:io' show Platform, stdout; |
| 50 * | 50 * |
| 51 * void main() { | 51 * void main() { |
| 52 * // Get the operating system as a string. | 52 * // Get the operating system as a string. |
| 53 * String os = Platform.operatingSystem; | 53 * String os = Platform.operatingSystem; |
| 54 * // Or, use a predicate getter. | 54 * // Or, use a predicate getter. |
| 55 * if (Platform.isMacOS) { | 55 * if (Platform.isMacOS) { |
| 56 * Print('is a Mac'); | 56 * Print('is a Mac'); |
| 57 * } else { | 57 * } else { |
| 58 * print('is not a Mac'); | 58 * print('is not a Mac'); |
| 59 * } | 59 * } |
| 60 * } | 60 * } |
| 61 * | 61 * |
| 62 * ## Other resources | 62 * ## Other resources |
| 63 * | 63 * |
| 64 * [Dart by Example](https://www.dartlang.org/dart-by-example/#dart-io-and-comma
nd-line-apps) | 64 * [Dart by Example](https://www.dartlang.org/dart-by-example/#dart-io-and-comma
nd-line-apps) |
| 65 * provides additional task-oriented code samples that show how to use | 65 * provides additional task-oriented code samples that show how to use |
| 66 * various API from the [dart:io] library. | 66 * various API from the [dart:io] library. |
| 67 */ | 67 */ |
| 68 class Platform { | 68 class Platform { |
| 69 static final _numberOfProcessors = _Platform.numberOfProcessors; | 69 static final _numberOfProcessors = _Platform.numberOfProcessors; |
| 70 static final _pathSeparator = _Platform.pathSeparator; | 70 static final _pathSeparator = _Platform.pathSeparator; |
| 71 static final _operatingSystem = _Platform.operatingSystem; | 71 static final _operatingSystem = _Platform.operatingSystem; |
| 72 static final _localHostname = _Platform.localHostname; | 72 static final _localHostname = _Platform.localHostname; |
| 73 static final _version = _Platform.version; | 73 static final _version = _Platform.version; |
| 74 | 74 |
| 75 /** | 75 /** |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 * returned on Windows is therefore case-insensitive and will convert | 124 * returned on Windows is therefore case-insensitive and will convert |
| 125 * all keys to upper case. On other platforms the returned map is | 125 * all keys to upper case. On other platforms the returned map is |
| 126 * a standard case-sensitive map. | 126 * a standard case-sensitive map. |
| 127 */ | 127 */ |
| 128 static Map<String, String> get environment => _Platform.environment; | 128 static Map<String, String> get environment => _Platform.environment; |
| 129 | 129 |
| 130 /** | 130 /** |
| 131 * Returns the path of the executable used to run the script in this | 131 * Returns the path of the executable used to run the script in this |
| 132 * isolate. | 132 * isolate. |
| 133 * | 133 * |
| 134 * If supported by the platform the returned path will be absolute. |
| 135 * |
| 134 * If the execution environment does not support [executable] an empty | 136 * If the execution environment does not support [executable] an empty |
| 135 * string is returned. | 137 * string is returned. |
| 136 */ | 138 */ |
| 137 static String get executable => _Platform.executable; | 139 static String get executable => _Platform.executable; |
| 138 | 140 |
| 139 /** | 141 /** |
| 140 * Returns the absolute URI of the script being run in this | 142 * Returns the absolute URI of the script being run in this |
| 141 * isolate. | 143 * isolate. |
| 142 * | 144 * |
| 143 * If the script argument on the command line is relative, | 145 * If the script argument on the command line is relative, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 174 /** | 176 /** |
| 175 * Returns the version of the current Dart runtime. | 177 * Returns the version of the current Dart runtime. |
| 176 * | 178 * |
| 177 * The returned `String` is formatted as the | 179 * The returned `String` is formatted as the |
| 178 * [semver](http://semver.org) version string of the current dart | 180 * [semver](http://semver.org) version string of the current dart |
| 179 * runtime, possibly followed by whitespace and other version and | 181 * runtime, possibly followed by whitespace and other version and |
| 180 * build details. | 182 * build details. |
| 181 */ | 183 */ |
| 182 static String get version => _version; | 184 static String get version => _version; |
| 183 } | 185 } |
| OLD | NEW |