Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(992)

Unified Diff: sdk/lib/io/process.dart

Issue 15299004: Add Process.shell and Process.runShell. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove Process.shell and clean up impl. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/standalone/io/process_echo_util.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | tests/standalone/io/process_echo_util.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698