| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 patch class _WindowsCodePageDecoder { | 5 patch class _WindowsCodePageDecoder { |
| 6 /* patch */ static String _decodeBytes(List<int> bytes) | 6 /* patch */ static String _decodeBytes(List<int> bytes) |
| 7 native "SystemEncodingToString"; | 7 native "SystemEncodingToString"; |
| 8 } | 8 } |
| 9 | 9 |
| 10 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 String _errorMessage; // Set to OS error message if process start failed. | 62 String _errorMessage; // Set to OS error message if process start failed. |
| 63 } | 63 } |
| 64 | 64 |
| 65 | 65 |
| 66 class _ProcessImpl extends NativeFieldWrapperClass1 implements Process { | 66 class _ProcessImpl extends NativeFieldWrapperClass1 implements Process { |
| 67 _ProcessImpl(String path, | 67 _ProcessImpl(String path, |
| 68 List<String> arguments, | 68 List<String> arguments, |
| 69 String this._workingDirectory, | 69 String this._workingDirectory, |
| 70 Map<String, String> environment, | 70 Map<String, String> environment, |
| 71 bool runInShell) { | 71 bool runInShell) { |
| 72 if (identical(runInShell, true)) { | 72 runInShell = identical(runInShell, true); |
| 73 if (runInShell) { |
| 73 arguments = _getShellArguments(path, arguments); | 74 arguments = _getShellArguments(path, arguments); |
| 74 path = _getShellCommand(); | 75 path = _getShellCommand(); |
| 75 } | 76 } |
| 76 | 77 |
| 77 if (path is !String) { | 78 if (path is !String) { |
| 78 throw new ArgumentError("Path is not a String: $path"); | 79 throw new ArgumentError("Path is not a String: $path"); |
| 79 } | 80 } |
| 80 _path = path; | 81 _path = path; |
| 81 | 82 |
| 82 if (arguments is !List) { | 83 if (arguments is !List) { |
| 83 throw new ArgumentError("Arguments is not a List: $arguments"); | 84 throw new ArgumentError("Arguments is not a List: $arguments"); |
| 84 } | 85 } |
| 85 int len = arguments.length; | 86 int len = arguments.length; |
| 86 _arguments = new List<String>(len); | 87 _arguments = new List<String>(len); |
| 87 for (int i = 0; i < len; i++) { | 88 for (int i = 0; i < len; i++) { |
| 88 var arg = arguments[i]; | 89 var arg = arguments[i]; |
| 89 if (arg is !String) { | 90 if (arg is !String) { |
| 90 throw new ArgumentError("Non-string argument: $arg"); | 91 throw new ArgumentError("Non-string argument: $arg"); |
| 91 } | 92 } |
| 92 _arguments[i] = arguments[i]; | 93 _arguments[i] = arguments[i]; |
| 93 if (Platform.operatingSystem == 'windows') { | 94 if (Platform.operatingSystem == 'windows') { |
| 94 _arguments[i] = _windowsArgumentEscape(_arguments[i]); | 95 _arguments[i] = _windowsArgumentEscape(_arguments[i], |
| 96 shellEscape: runInShell); |
| 95 } | 97 } |
| 96 } | 98 } |
| 97 | 99 |
| 98 if (_workingDirectory != null && _workingDirectory is !String) { | 100 if (_workingDirectory != null && _workingDirectory is !String) { |
| 99 throw new ArgumentError( | 101 throw new ArgumentError( |
| 100 "WorkingDirectory is not a String: $_workingDirectory"); | 102 "WorkingDirectory is not a String: $_workingDirectory"); |
| 101 } | 103 } |
| 102 | 104 |
| 103 if (environment != null) { | 105 if (environment != null) { |
| 104 var env = environment; | 106 var env = environment; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 shellArguments.add("-c"); | 151 shellArguments.add("-c"); |
| 150 for (var arg in arguments) { | 152 for (var arg in arguments) { |
| 151 arg = arg.replaceAll("'", "'\"'\"'"); | 153 arg = arg.replaceAll("'", "'\"'\"'"); |
| 152 commandLine.write(" '$arg'"); | 154 commandLine.write(" '$arg'"); |
| 153 } | 155 } |
| 154 shellArguments.add(commandLine.toString()); | 156 shellArguments.add(commandLine.toString()); |
| 155 } | 157 } |
| 156 return shellArguments; | 158 return shellArguments; |
| 157 } | 159 } |
| 158 | 160 |
| 159 String _windowsArgumentEscape(String argument) { | 161 String _windowsArgumentEscape(String argument, { bool shellEscape: false }) { |
| 160 var result = argument; | 162 var result = argument; |
| 161 if (argument.contains('\t') || | 163 if (argument.contains('\t') || |
| 162 argument.contains(' ') || | 164 argument.contains(' ') || |
| 163 argument.contains('"')) { | 165 // TODO(ajohnsen): Remove shellEscape. |
| 166 (shellEscape && argument.contains('"'))) { |
| 164 // Produce something that the C runtime on Windows will parse | 167 // Produce something that the C runtime on Windows will parse |
| 165 // back as this string. | 168 // back as this string. |
| 166 | 169 |
| 167 // Replace any number of '\' followed by '"' with | 170 // Replace any number of '\' followed by '"' with |
| 168 // twice as many '\' followed by '\"'. | 171 // twice as many '\' followed by '\"'. |
| 169 var backslash = '\\'.codeUnitAt(0); | 172 var backslash = '\\'.codeUnitAt(0); |
| 170 var sb = new StringBuffer(); | 173 var sb = new StringBuffer(); |
| 171 var nextPos = 0; | 174 var nextPos = 0; |
| 172 var quotePos = argument.indexOf('"', nextPos); | 175 var quotePos = argument.indexOf('"', nextPos); |
| 173 while (quotePos != -1) { | 176 while (quotePos != -1) { |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 const _ProcessResult(int this.pid, | 384 const _ProcessResult(int this.pid, |
| 382 int this.exitCode, | 385 int this.exitCode, |
| 383 String this.stdout, | 386 String this.stdout, |
| 384 String this.stderr); | 387 String this.stderr); |
| 385 | 388 |
| 386 final int pid; | 389 final int pid; |
| 387 final int exitCode; | 390 final int exitCode; |
| 388 final String stdout; | 391 final String stdout; |
| 389 final String stderr; | 392 final String stderr; |
| 390 } | 393 } |
| OLD | NEW |