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

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

Issue 10127008: 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
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) {
Søren Gjesse 2012/04/19 12:45:55 Maybe we should allow any type on value and just r
Søren Gjesse 2012/04/19 12:45:55 Check that the key does not contain illegal charct
Søren Gjesse 2012/04/19 12:45:55 For both key and value.toString() is there any cha
Mads Ager (google) 2012/04/20 12:24:51 I would like to start out requiring this to be a M
Mads Ager (google) 2012/04/20 12:24:51 An early check for that would make sense, thanks.
Mads Ager (google) 2012/04/20 12:24:51 Yes, at this point if you go out of ASCII range th
79 throw new IllegalArgumentException(
80 "Environment key or value is not a string: ($key, $value)");
81 }
82 _environment.add('$key=$value');
83 });
84 }
85
71 _in = new _Socket._internalReadOnly(); // stdout coming from process. 86 _in = new _Socket._internalReadOnly(); // stdout coming from process.
72 _out = new _Socket._internalWriteOnly(); // stdin going to process. 87 _out = new _Socket._internalWriteOnly(); // stdin going to process.
73 _err = new _Socket._internalReadOnly(); // stderr coming from process. 88 _err = new _Socket._internalReadOnly(); // stderr coming from process.
74 _exitHandler = new _Socket._internalReadOnly(); 89 _exitHandler = new _Socket._internalReadOnly();
75 _closed = false; 90 _closed = false;
76 _killed = false; 91 _killed = false;
77 _started = false; 92 _started = false;
78 _onExit = null; 93 _onExit = null;
79 // TODO(ager): Make the actual process starting really async instead of 94 // TODO(ager): Make the actual process starting really async instead of
80 // simulating it with a timer. 95 // simulating it with a timer.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 (bytes[offset + 1] << 8) + 147 (bytes[offset + 1] << 8) +
133 (bytes[offset + 2] << 16) + 148 (bytes[offset + 2] << 16) +
134 (bytes[offset + 3] << 24)); 149 (bytes[offset + 3] << 24));
135 } 150 }
136 151
137 void start() { 152 void start() {
138 var status = new _ProcessStartStatus(); 153 var status = new _ProcessStartStatus();
139 bool success = _start(_path, 154 bool success = _start(_path,
140 _arguments, 155 _arguments,
141 _workingDirectory, 156 _workingDirectory,
157 _environment,
142 _in, 158 _in,
143 _out, 159 _out,
144 _err, 160 _err,
145 _exitHandler, 161 _exitHandler,
146 status); 162 status);
147 if (!success) { 163 if (!success) {
148 close(); 164 close();
149 if (_onError !== null) { 165 if (_onError !== null) {
150 _onError(new ProcessException(status._errorMessage, status._errorCode)); 166 _onError(new ProcessException(status._errorMessage, status._errorCode));
151 return; 167 return;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 }; 201 };
186 202
187 if (_onStart !== null) { 203 if (_onStart !== null) {
188 _onStart(); 204 _onStart();
189 } 205 }
190 } 206 }
191 207
192 bool _start(String path, 208 bool _start(String path,
193 List<String> arguments, 209 List<String> arguments,
194 String workingDirectory, 210 String workingDirectory,
211 List<String> environment,
195 Socket input, 212 Socket input,
196 Socket output, 213 Socket output,
197 Socket error, 214 Socket error,
198 Socket exitHandler, 215 Socket exitHandler,
199 _ProcessStartStatus status) native "Process_Start"; 216 _ProcessStartStatus status) native "Process_Start";
200 217
201 InputStream get stdout() { 218 InputStream get stdout() {
202 if (_closed) { 219 if (_closed) {
203 throw new ProcessException("Process closed"); 220 throw new ProcessException("Process closed");
204 } 221 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 _onError = callback; 284 _onError = callback;
268 } 285 }
269 286
270 void set onStart(void callback()) { 287 void set onStart(void callback()) {
271 _onStart = callback; 288 _onStart = callback;
272 } 289 }
273 290
274 String _path; 291 String _path;
275 ObjectArray<String> _arguments; 292 ObjectArray<String> _arguments;
276 String _workingDirectory; 293 String _workingDirectory;
294 List<String> _environment;
277 // Private methods of _Socket are used by _in, _out, and _err. 295 // Private methods of _Socket are used by _in, _out, and _err.
278 _Socket _in; 296 _Socket _in;
279 _Socket _out; 297 _Socket _out;
280 _Socket _err; 298 _Socket _err;
281 Socket _exitHandler; 299 Socket _exitHandler;
282 int _pid; 300 int _pid;
283 bool _closed; 301 bool _closed;
284 bool _killed; 302 bool _killed;
285 bool _started; 303 bool _started;
286 Function _onExit; 304 Function _onExit;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 void close() => _process.close(); 414 void close() => _process.close();
397 415
398 Process _process; 416 Process _process;
399 Function _callback; 417 Function _callback;
400 StringBuffer _stdoutBuffer; 418 StringBuffer _stdoutBuffer;
401 StringBuffer _stderrBuffer; 419 StringBuffer _stderrBuffer;
402 int _exitCode; 420 int _exitCode;
403 bool _stdoutClosed = false; 421 bool _stdoutClosed = false;
404 bool _stderrClosed = false; 422 bool _stderrClosed = false;
405 } 423 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698