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..c9a8011abe75b1717cc9d60f8c7d7beac3eadbdb 100644 |
| --- a/sdk/lib/io/process.dart |
| +++ b/sdk/lib/io/process.dart |
| @@ -100,6 +100,53 @@ abstract class Process { |
| [ProcessOptions options]); |
| /** |
| + * Starts a process in the system shell and runs it non-interactively to |
| + * completion. |
| + * |
| + * 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.
|
| + * 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 r"%WINDIR%\system32\cmd.exe"; |
| + } |
| + return "/bin/sh"; |
| + } |
| + |
| + static List<String> _getShellArguments(String executable, |
| + List<String> arguments) { |
| + List<String> shellArguments = []; |
| + if (Platform.operatingSystem == 'windows') { |
| + shellArguments.add("/k"); |
| + } else { |
| + shellArguments.add("-c"); |
| + } |
| + var commandLine = new StringBuffer(); |
| + commandLine.write(executable); |
| + for (var arg in arguments) { |
| + arg = arg.replaceAll("'", "'\"'\"'"); |
| + commandLine.write(" '$arg'"); |
| + } |
| + shellArguments.add(commandLine.toString()); |
| + print(shellArguments); |
| + return shellArguments; |
| + } |
| + |
| + /** |
| * Returns the standard output stream of the process as a [:Stream:]. |
| * |
| * Throws an [UnsupportedError] if the process is |