Chromium Code Reviews| Index: sdk/lib/io/process.dart |
| diff --git a/sdk/lib/io/process.dart b/sdk/lib/io/process.dart |
| index c1a060a556ffdba90ab40e2047814ff809df194a..6e9b1cd1252eae66dbaa3b2ef26d74a028cba3f2 100644 |
| --- a/sdk/lib/io/process.dart |
| +++ b/sdk/lib/io/process.dart |
| @@ -100,6 +100,57 @@ abstract class Process { |
| [ProcessOptions options]); |
| /** |
| + * Starts a process in the system shell and runs it non-interactively to |
| + * completion. |
| + * |
| + * On Linux and Mac OS, [:/bin/sh:] is used to execute the [executable]. |
| + * On Windows, [:%WINDIR%\system32\cmd.exe:] is used. |
| + * |
| + * An optional [ProcessOptions] object can be passed to specify |
| + * options other than the executable and the arguments. |
| + * |
| + * Returns a [:Future<ProcessResult>:] that completes with the |
| + * result of running the process, i.e., exit code, standard out and |
| + * standard in. |
| + */ |
| + static Future<ProcessResult> runShell(String executable, |
| + List<String> arguments, |
| + [ProcessOptions options]) |
| + => run(_getShellCommand(), |
| + _getShellArguments(executable, arguments), |
| + options); |
| + |
| + static String _getShellCommand() { |
| + if (Platform.operatingSystem == 'windows') { |
| + return 'cmd.exe'; |
| + } |
| + return '/bin/sh'; |
| + } |
| + |
| + static List<String> _getShellArguments(String executable, |
| + List<String> arguments) { |
| + List<String> shellArguments = []; |
| + if (Platform.operatingSystem == 'windows') { |
| + shellArguments.add('/c'); |
| + shellArguments.add(executable); |
| + for (var arg in arguments) { |
| + arg = arg.replaceAll('"', r'\"'); |
| + shellArguments.add(arg); |
| + } |
| + } else { |
| + var commandLine = new StringBuffer(); |
| + commandLine.write(executable); |
| + shellArguments.add("-c"); |
| + for (var arg in arguments) { |
| + 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
|
| + commandLine.write(" '$arg'"); |
| + } |
| + shellArguments.add(commandLine.toString()); |
| + } |
| + return shellArguments; |
| + } |
| + |
| + /** |
| * Returns the standard output stream of the process as a [:Stream:]. |
| * |
| * Throws an [UnsupportedError] if the process is |