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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 * An optional [ProcessOptions] object can be passed to specify | 91 * An optional [ProcessOptions] object can be passed to specify |
| 92 * options other than the executable and the arguments. | 92 * options other than the executable and the arguments. |
| 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 |
|
Søren Gjesse
2013/05/17 14:48:56
This method needs a comment.
Should there be a wa
Anders Johnsen
2013/05/22 07:45:51
Done.
| |
| 102 static Future<ProcessResult> runShell(String executable, | |
| 103 List<String> arguments, | |
| 104 [ProcessOptions options]) | |
| 105 => run(_getShellCommand(), | |
| 106 _getShellArguments(executable, arguments), | |
| 107 options); | |
| 108 | |
|
Søren Gjesse
2013/05/17 14:48:56
I am not sure we should have both runShell and she
Anders Johnsen
2013/05/22 07:45:51
Done.
| |
| 109 static Future<ProcessResult> shell(String command, | |
|
kustermann
2013/05/21 07:50:00
What is this method doing?
Anders Johnsen
2013/05/22 07:45:51
It's gone.
| |
| 110 [ProcessOptions options]) | |
| 111 => run(_getShellCommand(), | |
| 112 _getShellArguments(command, []), | |
| 113 options); | |
| 114 | |
| 115 static String _getShellCommand() { | |
|
Søren Gjesse
2013/05/17 14:48:56
Maybe we should do more extensive search of the sh
Anders Johnsen
2013/05/22 07:45:51
Done.
| |
| 116 if (Platform.operatingSystem == 'windows') { | |
| 117 return "cmd"; | |
|
Søren Gjesse
2013/05/17 14:48:56
Should we lookup %COMSPEC% in the Windows environm
Anders Johnsen
2013/05/22 07:45:51
Done.
| |
| 118 } | |
| 119 return "sh"; | |
|
Søren Gjesse
2013/05/17 14:48:56
Should we lookup $SHELL in the environment? Should
ricow1
2013/05/21 07:26:34
I don't really care what it defaults to, but I do
kustermann
2013/05/21 07:50:00
The issue here is that different shells might inte
Anders Johnsen
2013/05/22 07:45:51
Done.
| |
| 120 } | |
| 121 | |
| 122 static List<String> _getShellArguments(String executable, | |
| 123 List<String> arguments) { | |
| 124 List<String> shellArguments = []; | |
| 125 if (Platform.operatingSystem == 'windows') { | |
| 126 shellArguments.add("/k"); | |
| 127 } else { | |
| 128 shellArguments.add("-c"); | |
| 129 } | |
| 130 var commandLine = executable; | |
| 131 for (var arg in arguments) { | |
| 132 arg = arg.replaceAll("'", "'\"'\"'"); | |
|
Lasse Reichstein Nielsen
2013/05/21 07:31:51
You could use a multiline string here:
"""'"'"'"
Anders Johnsen
2013/05/22 07:45:51
Hehe, I prefer not ;)
| |
| 133 commandLine = "$commandLine '$arg'"; | |
|
Lasse Reichstein Nielsen
2013/05/21 07:13:42
Quadratic time string concatenation. Use a StringB
Anders Johnsen
2013/05/22 07:45:51
Done.
| |
| 134 } | |
| 135 shellArguments.add(commandLine); | |
| 136 return shellArguments; | |
| 137 } | |
| 138 | |
| 102 /** | 139 /** |
| 103 * Returns the standard output stream of the process as a [:Stream:]. | 140 * Returns the standard output stream of the process as a [:Stream:]. |
| 104 * | 141 * |
| 105 * Throws an [UnsupportedError] if the process is | 142 * Throws an [UnsupportedError] if the process is |
| 106 * non-interactive. | 143 * non-interactive. |
| 107 */ | 144 */ |
| 108 Stream<List<int>> get stdout; | 145 Stream<List<int>> get stdout; |
| 109 | 146 |
| 110 /** | 147 /** |
| 111 * Returns the standard error stream of the process as a [:Stream:]. | 148 * Returns the standard error stream of the process as a [:Stream:]. |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 /** | 327 /** |
| 291 * Contains the system message for the process exception if any. | 328 * Contains the system message for the process exception if any. |
| 292 */ | 329 */ |
| 293 final String message; | 330 final String message; |
| 294 | 331 |
| 295 /** | 332 /** |
| 296 * Contains the OS error code for the process exception if any. | 333 * Contains the OS error code for the process exception if any. |
| 297 */ | 334 */ |
| 298 final int errorCode; | 335 final int errorCode; |
| 299 } | 336 } |
| OLD | NEW |