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 Linux and Mac OS, [:/bin/sh:] is used to execute the [executable]. | |
| 107 * On 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 '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('/c'); | |
| 135 shellArguments.add(executable); | |
| 136 for (var arg in arguments) { | |
| 137 arg = arg.replaceAll('"', r'\"'); | |
| 138 shellArguments.add(arg); | |
| 139 } | |
| 140 } else { | |
| 141 var commandLine = new StringBuffer(); | |
| 142 commandLine.write(executable); | |
| 143 shellArguments.add("-c"); | |
| 144 for (var arg in arguments) { | |
| 145 arg = arg.replaceAll("'", "'\"'\"'"); | |
|
kustermann
2013/05/22 11:54:26
I think there is something fishy with this replace
Anders Johnsen
2013/05/22 12:58:25
See https://codereview.chromium.org/15743002
| |
| 146 commandLine.write(" '$arg'"); | |
| 147 } | |
| 148 shellArguments.add(commandLine.toString()); | |
| 149 } | |
| 150 return shellArguments; | |
| 151 } | |
| 152 | |
| 153 /** | |
| 103 * Returns the standard output stream of the process as a [:Stream:]. | 154 * Returns the standard output stream of the process as a [:Stream:]. |
| 104 * | 155 * |
| 105 * Throws an [UnsupportedError] if the process is | 156 * Throws an [UnsupportedError] if the process is |
| 106 * non-interactive. | 157 * non-interactive. |
| 107 */ | 158 */ |
| 108 Stream<List<int>> get stdout; | 159 Stream<List<int>> get stdout; |
| 109 | 160 |
| 110 /** | 161 /** |
| 111 * Returns the standard error stream of the process as a [:Stream:]. | 162 * Returns the standard error stream of the process as a [:Stream:]. |
| 112 * | 163 * |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 /** | 341 /** |
| 291 * Contains the system message for the process exception if any. | 342 * Contains the system message for the process exception if any. |
| 292 */ | 343 */ |
| 293 final String message; | 344 final String message; |
| 294 | 345 |
| 295 /** | 346 /** |
| 296 * Contains the OS error code for the process exception if any. | 347 * Contains the OS error code for the process exception if any. |
| 297 */ | 348 */ |
| 298 final int errorCode; | 349 final int errorCode; |
| 299 } | 350 } |
| OLD | NEW |