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

Side by Side Diff: runtime/bin/process_impl.dart

Issue 10166029: Support passing an environment variable map to child processes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/process.dart ('k') | runtime/bin/process_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 class _ProcessStartStatus { 5 class _ProcessStartStatus {
6 int _errorCode; // Set to OS error code if process start failed. 6 int _errorCode; // Set to OS error code if process start failed.
7 String _errorMessage; // Set to OS error message if process start failed. 7 String _errorMessage; // Set to OS error message if process start failed.
8 } 8 }
9 9
10 10
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 } 61 }
62 62
63 if (options !== null && options.workingDirectory !== null) { 63 if (options !== null && options.workingDirectory !== null) {
64 _workingDirectory = options.workingDirectory; 64 _workingDirectory = options.workingDirectory;
65 if (_workingDirectory is !String) { 65 if (_workingDirectory is !String) {
66 throw new IllegalArgumentException( 66 throw new IllegalArgumentException(
67 "WorkingDirectory is not a String: $_workingDirectory"); 67 "WorkingDirectory is not a String: $_workingDirectory");
68 } 68 }
69 } 69 }
70 70
71 if (options !== null && options.environment !== null) {
72 var env = options.environment;
73 if (env is !Map) {
74 throw new IllegalArgumentException("Environment is not a map: $env");
75 }
76 _environment = [];
77 env.forEach((key, value) {
78 if (key is !String || value is !String) {
79 throw new IllegalArgumentException(
80 "Environment key or value is not a string: ($key, $value)");
81 }
82 if (key.contains('=')) {
83 throw new IllegalArgumentException(
84 "Environment keys may not contain '=': $key");
85 }
86 _environment.add('$key=$value');
87 });
88 }
89
71 _in = new _Socket._internalReadOnly(); // stdout coming from process. 90 _in = new _Socket._internalReadOnly(); // stdout coming from process.
72 _out = new _Socket._internalWriteOnly(); // stdin going to process. 91 _out = new _Socket._internalWriteOnly(); // stdin going to process.
73 _err = new _Socket._internalReadOnly(); // stderr coming from process. 92 _err = new _Socket._internalReadOnly(); // stderr coming from process.
74 _exitHandler = new _Socket._internalReadOnly(); 93 _exitHandler = new _Socket._internalReadOnly();
75 _closed = false; 94 _closed = false;
76 _killed = false; 95 _killed = false;
77 _started = false; 96 _started = false;
78 _onExit = null; 97 _onExit = null;
79 // TODO(ager): Make the actual process starting really async instead of 98 // TODO(ager): Make the actual process starting really async instead of
80 // simulating it with a timer. 99 // simulating it with a timer.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 (bytes[offset + 1] << 8) + 151 (bytes[offset + 1] << 8) +
133 (bytes[offset + 2] << 16) + 152 (bytes[offset + 2] << 16) +
134 (bytes[offset + 3] << 24)); 153 (bytes[offset + 3] << 24));
135 } 154 }
136 155
137 void start() { 156 void start() {
138 var status = new _ProcessStartStatus(); 157 var status = new _ProcessStartStatus();
139 bool success = _start(_path, 158 bool success = _start(_path,
140 _arguments, 159 _arguments,
141 _workingDirectory, 160 _workingDirectory,
161 _environment,
142 _in, 162 _in,
143 _out, 163 _out,
144 _err, 164 _err,
145 _exitHandler, 165 _exitHandler,
146 status); 166 status);
147 if (!success) { 167 if (!success) {
148 close(); 168 close();
149 if (_onError !== null) { 169 if (_onError !== null) {
150 _onError(new ProcessException(status._errorMessage, status._errorCode)); 170 _onError(new ProcessException(status._errorMessage, status._errorCode));
151 return; 171 return;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 }; 205 };
186 206
187 if (_onStart !== null) { 207 if (_onStart !== null) {
188 _onStart(); 208 _onStart();
189 } 209 }
190 } 210 }
191 211
192 bool _start(String path, 212 bool _start(String path,
193 List<String> arguments, 213 List<String> arguments,
194 String workingDirectory, 214 String workingDirectory,
215 List<String> environment,
195 Socket input, 216 Socket input,
196 Socket output, 217 Socket output,
197 Socket error, 218 Socket error,
198 Socket exitHandler, 219 Socket exitHandler,
199 _ProcessStartStatus status) native "Process_Start"; 220 _ProcessStartStatus status) native "Process_Start";
200 221
201 InputStream get stdout() { 222 InputStream get stdout() {
202 if (_closed) { 223 if (_closed) {
203 throw new ProcessException("Process closed"); 224 throw new ProcessException("Process closed");
204 } 225 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 _onError = callback; 288 _onError = callback;
268 } 289 }
269 290
270 void set onStart(void callback()) { 291 void set onStart(void callback()) {
271 _onStart = callback; 292 _onStart = callback;
272 } 293 }
273 294
274 String _path; 295 String _path;
275 ObjectArray<String> _arguments; 296 ObjectArray<String> _arguments;
276 String _workingDirectory; 297 String _workingDirectory;
298 List<String> _environment;
277 // Private methods of _Socket are used by _in, _out, and _err. 299 // Private methods of _Socket are used by _in, _out, and _err.
278 _Socket _in; 300 _Socket _in;
279 _Socket _out; 301 _Socket _out;
280 _Socket _err; 302 _Socket _err;
281 Socket _exitHandler; 303 Socket _exitHandler;
282 int _pid; 304 int _pid;
283 bool _closed; 305 bool _closed;
284 bool _killed; 306 bool _killed;
285 bool _started; 307 bool _started;
286 Function _onExit; 308 Function _onExit;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 void close() => _process.close(); 418 void close() => _process.close();
397 419
398 Process _process; 420 Process _process;
399 Function _callback; 421 Function _callback;
400 StringBuffer _stdoutBuffer; 422 StringBuffer _stdoutBuffer;
401 StringBuffer _stderrBuffer; 423 StringBuffer _stderrBuffer;
402 int _exitCode; 424 int _exitCode;
403 bool _stdoutClosed = false; 425 bool _stdoutClosed = false;
404 bool _stderrClosed = false; 426 bool _stderrClosed = false;
405 } 427 }
OLDNEW
« no previous file with comments | « runtime/bin/process.dart ('k') | runtime/bin/process_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698