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

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

Issue 9108008: Add optional workingDirectory argument to Process.start. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 11 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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
11 class _Process implements Process { 11 class _Process implements Process {
12 12
13 _Process.start(String path, List<String> arguments) { 13 _Process.start(String path, List<String> arguments, [String workingDirectory]) {
Søren Gjesse 2012/01/05 09:30:47 Ling line, do either _Process.start( String p
Anders Johnsen 2012/01/05 09:50:49 Done.
14 if (path is !String) { 14 if (path is !String) {
15 throw new ProcessException("Path is not a String: $path"); 15 throw new ProcessException("Path is not a String: $path");
16 } 16 }
17 _path = path; 17 _path = path;
18 18
19 if (arguments is !List) { 19 if (arguments is !List) {
20 throw new ProcessException("Arguments is not a List: $arguments"); 20 throw new ProcessException("Arguments is not a List: $arguments");
21 } 21 }
22 int len = arguments.length; 22 int len = arguments.length;
23 _arguments = new ObjectArray<String>(len); 23 _arguments = new ObjectArray<String>(len);
24 for (int i = 0; i < len; i++) { 24 for (int i = 0; i < len; i++) {
25 var arg = arguments[i]; 25 var arg = arguments[i];
26 if (arg is !String) { 26 if (arg is !String) {
27 throw new ProcessException("Non-string argument: $arg"); 27 throw new ProcessException("Non-string argument: $arg");
28 } 28 }
29 _arguments[i] = arguments[i]; 29 _arguments[i] = arguments[i];
30 } 30 }
31 31
32 if (workingDirectory is !String && workingDirectory !== null) {
33 throw new ProcessException(
34 "WorkingDirectory is not a String: $workingDirectory");
35 }
36 _workingDirectory = workingDirectory;
37
32 _in = new _Socket._internalReadOnly(); // stdout coming from process. 38 _in = new _Socket._internalReadOnly(); // stdout coming from process.
33 _out = new _Socket._internalWriteOnly(); // stdin going to process. 39 _out = new _Socket._internalWriteOnly(); // stdin going to process.
34 _err = new _Socket._internalReadOnly(); // stderr coming from process. 40 _err = new _Socket._internalReadOnly(); // stderr coming from process.
35 _exitHandler = new _Socket._internalReadOnly(); 41 _exitHandler = new _Socket._internalReadOnly();
36 _closed = false; 42 _closed = false;
37 _killed = false; 43 _killed = false;
38 _started = false; 44 _started = false;
39 _exitHandlerCallback = null; 45 _exitHandlerCallback = null;
40 // TODO(ager): Make the actual process starting really async instead of 46 // TODO(ager): Make the actual process starting really async instead of
41 // simulating it with a timer. 47 // simulating it with a timer.
42 new Timer((Timer ignore) => start(), 0); 48 new Timer((Timer ignore) => start(), 0);
43 } 49 }
44 50
45 int _intFromBytes(List<int> bytes, int offset) { 51 int _intFromBytes(List<int> bytes, int offset) {
46 return (bytes[offset] + 52 return (bytes[offset] +
47 (bytes[offset + 1] << 8) + 53 (bytes[offset + 1] << 8) +
48 (bytes[offset + 2] << 16) + 54 (bytes[offset + 2] << 16) +
49 (bytes[offset + 3] << 24)); 55 (bytes[offset + 3] << 24));
50 } 56 }
51 57
52 void start() { 58 void start() {
53 var status = new _ProcessStartStatus(); 59 var status = new _ProcessStartStatus();
54 bool success = _start( 60 bool success = _start(
Søren Gjesse 2012/01/05 09:30:47 When all arguments cannot fit on one line they sho
Anders Johnsen 2012/01/05 09:50:49 Nice to know, ty!
55 _path, _arguments, _in, _out, _err, _exitHandler, status); 61 _path, _arguments, _workingDirectory, _in, _out, _err, _exitHandler,
62 status);
56 if (!success) { 63 if (!success) {
57 close(); 64 close();
58 if (_errorHandler !== null) { 65 if (_errorHandler !== null) {
59 _errorHandler(new ProcessException(status._errorMessage, 66 _errorHandler(new ProcessException(status._errorMessage,
60 status._errorCode)); 67 status._errorCode));
61 return; 68 return;
62 } 69 }
63 } 70 }
64 _started = true; 71 _started = true;
65 72
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 if (exitDataRead == EXIT_DATA_SIZE) handleExit(); 106 if (exitDataRead == EXIT_DATA_SIZE) handleExit();
100 }; 107 };
101 108
102 if (_startHandler !== null) { 109 if (_startHandler !== null) {
103 _startHandler(); 110 _startHandler();
104 } 111 }
105 } 112 }
106 113
107 bool _start(String path, 114 bool _start(String path,
108 List<String> arguments, 115 List<String> arguments,
116 String workingDirectory,
109 Socket input, 117 Socket input,
110 Socket output, 118 Socket output,
111 Socket error, 119 Socket error,
112 Socket exitHandler, 120 Socket exitHandler,
113 _ProcessStartStatus status) native "Process_Start"; 121 _ProcessStartStatus status) native "Process_Start";
114 122
115 void _processExit(int pid) native "Process_Exit"; 123 void _processExit(int pid) native "Process_Exit";
116 124
117 InputStream get stdout() { 125 InputStream get stdout() {
118 if (_closed) { 126 if (_closed) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 void set errorHandler(void callback(ProcessException exception)) { 188 void set errorHandler(void callback(ProcessException exception)) {
181 _errorHandler = callback; 189 _errorHandler = callback;
182 } 190 }
183 191
184 void set startHandler(void callback()) { 192 void set startHandler(void callback()) {
185 _startHandler = callback; 193 _startHandler = callback;
186 } 194 }
187 195
188 String _path; 196 String _path;
189 ObjectArray<String> _arguments; 197 ObjectArray<String> _arguments;
198 String _workingDirectory;
190 Socket _in; 199 Socket _in;
191 Socket _out; 200 Socket _out;
192 Socket _err; 201 Socket _err;
193 Socket _exitHandler; 202 Socket _exitHandler;
194 int _pid; 203 int _pid;
195 bool _closed; 204 bool _closed;
196 bool _killed; 205 bool _killed;
197 bool _started; 206 bool _started;
198 Function _exitHandlerCallback; 207 Function _exitHandlerCallback;
199 Function _errorHandler; 208 Function _errorHandler;
200 Function _startHandler; 209 Function _startHandler;
201 } 210 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698