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

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: Fix Windows 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..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
« 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