Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // TODO(ager): The only reason for this class is that we | 7 // TODO(ager): The only reason for this class is that we |
| 8 // cannot patch a top-level at this point. | 8 // cannot patch a top-level at this point. |
| 9 class _ProcessUtils { | 9 class _ProcessUtils { |
| 10 external static void _exit(int status); | 10 external static void _exit(int status); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 * | 93 * |
| 94 * Returns a [:Future<ProcessResult>:] that completes with the | 94 * Returns a [:Future<ProcessResult>:] that completes with the |
| 95 * result of running the process, i.e., exit code, standard out and | 95 * result of running the process, i.e., exit code, standard out and |
| 96 * standard in. | 96 * standard in. |
| 97 */ | 97 */ |
| 98 external static Future<ProcessResult> run(String executable, | 98 external static Future<ProcessResult> run(String executable, |
| 99 List<String> arguments, | 99 List<String> arguments, |
| 100 [ProcessOptions options]); | 100 [ProcessOptions options]); |
| 101 | 101 |
| 102 /** | 102 /** |
| 103 * Starts a process in the system shell and runs it non-interactively to | |
| 104 * completion. | |
| 105 * | |
| 106 * On UNIX systems, [:/bin/sh:] is used to execute the [executable]. On | |
|
Søren Gjesse
2013/05/22 07:50:39
UNIX -> Linux and Mac OS
Anders Johnsen
2013/05/22 07:53:07
Done.
| |
| 107 * Windows, [:%WINDIR%\system32\cmd.exe:] is used. | |
| 108 * | |
| 109 * An optional [ProcessOptions] object can be passed to specify | |
| 110 * options other than the executable and the arguments. | |
| 111 * | |
| 112 * Returns a [:Future<ProcessResult>:] that completes with the | |
| 113 * result of running the process, i.e., exit code, standard out and | |
| 114 * standard in. | |
| 115 */ | |
| 116 static Future<ProcessResult> runShell(String executable, | |
| 117 List<String> arguments, | |
| 118 [ProcessOptions options]) | |
| 119 => run(_getShellCommand(), | |
| 120 _getShellArguments(executable, arguments), | |
| 121 options); | |
| 122 | |
| 123 static String _getShellCommand() { | |
| 124 if (Platform.operatingSystem == 'windows') { | |
| 125 return r"%WINDIR%\system32\cmd.exe"; | |
| 126 } | |
| 127 return "/bin/sh"; | |
| 128 } | |
| 129 | |
| 130 static List<String> _getShellArguments(String executable, | |
| 131 List<String> arguments) { | |
| 132 List<String> shellArguments = []; | |
| 133 if (Platform.operatingSystem == 'windows') { | |
| 134 shellArguments.add("/k"); | |
| 135 } else { | |
| 136 shellArguments.add("-c"); | |
| 137 } | |
| 138 var commandLine = new StringBuffer(); | |
| 139 commandLine.write(executable); | |
| 140 for (var arg in arguments) { | |
| 141 arg = arg.replaceAll("'", "'\"'\"'"); | |
| 142 commandLine.write(" '$arg'"); | |
| 143 } | |
| 144 shellArguments.add(commandLine.toString()); | |
| 145 print(shellArguments); | |
| 146 return shellArguments; | |
| 147 } | |
| 148 | |
| 149 /** | |
| 103 * Returns the standard output stream of the process as a [:Stream:]. | 150 * Returns the standard output stream of the process as a [:Stream:]. |
| 104 * | 151 * |
| 105 * Throws an [UnsupportedError] if the process is | 152 * Throws an [UnsupportedError] if the process is |
| 106 * non-interactive. | 153 * non-interactive. |
| 107 */ | 154 */ |
| 108 Stream<List<int>> get stdout; | 155 Stream<List<int>> get stdout; |
| 109 | 156 |
| 110 /** | 157 /** |
| 111 * Returns the standard error stream of the process as a [:Stream:]. | 158 * Returns the standard error stream of the process as a [:Stream:]. |
| 112 * | 159 * |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 /** | 337 /** |
| 291 * Contains the system message for the process exception if any. | 338 * Contains the system message for the process exception if any. |
| 292 */ | 339 */ |
| 293 final String message; | 340 final String message; |
| 294 | 341 |
| 295 /** | 342 /** |
| 296 * Contains the OS error code for the process exception if any. | 343 * Contains the OS error code for the process exception if any. |
| 297 */ | 344 */ |
| 298 final int errorCode; | 345 final int errorCode; |
| 299 } | 346 } |
| OLD | NEW |