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

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: 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
Index: sdk/lib/io/process.dart
diff --git a/sdk/lib/io/process.dart b/sdk/lib/io/process.dart
index c1a060a556ffdba90ab40e2047814ff809df194a..381610a566159a17eb0e17a5af342c7f1d0167f6 100644
--- a/sdk/lib/io/process.dart
+++ b/sdk/lib/io/process.dart
@@ -99,6 +99,43 @@ abstract class Process {
List<String> arguments,
[ProcessOptions options]);
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.
+ static Future<ProcessResult> runShell(String executable,
+ List<String> arguments,
+ [ProcessOptions options])
+ => run(_getShellCommand(),
+ _getShellArguments(executable, arguments),
+ options);
+
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.
+ 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.
+ [ProcessOptions options])
+ => run(_getShellCommand(),
+ _getShellArguments(command, []),
+ options);
+
+ 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.
+ if (Platform.operatingSystem == 'windows') {
+ 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.
+ }
+ 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.
+ }
+
+ 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 = executable;
+ for (var arg in arguments) {
+ 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 ;)
+ 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.
+ }
+ shellArguments.add(commandLine);
+ return shellArguments;
+ }
+
/**
* Returns the standard output stream of the process as a [:Stream:].
*
« no previous file with comments | « no previous file | tests/standalone/io/process_echo_util.dart » ('j') | tests/standalone/io/process_shell_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698