Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 [ProcessOptions options]) { | 27 [ProcessOptions options]) { |
| 28 return _runNonInteractiveProcess(executable, arguments, options); | 28 return _runNonInteractiveProcess(executable, arguments, options); |
| 29 } | 29 } |
| 30 } | 30 } |
| 31 | 31 |
| 32 | 32 |
| 33 patch class _ProcessUtils { | 33 patch class _ProcessUtils { |
| 34 /* patch */ static _exit(int status) native "Process_Exit"; | 34 /* patch */ static _exit(int status) native "Process_Exit"; |
| 35 /* patch */ static _setExitCode(int status) native "Process_SetExitCode"; | 35 /* patch */ static _setExitCode(int status) native "Process_SetExitCode"; |
| 36 /* patch */ static _sleep(int millis) native "Process_Sleep"; | 36 /* patch */ static _sleep(int millis) native "Process_Sleep"; |
| 37 /* patch */ static _pid(Process process) native "Process_Pid"; | |
| 37 } | 38 } |
| 38 | 39 |
| 39 | 40 |
| 40 class _ProcessStartStatus { | 41 class _ProcessStartStatus { |
| 41 int _errorCode; // Set to OS error code if process start failed. | 42 int _errorCode; // Set to OS error code if process start failed. |
| 42 String _errorMessage; // Set to OS error message if process start failed. | 43 String _errorMessage; // Set to OS error message if process start failed. |
| 43 } | 44 } |
| 44 | 45 |
| 45 | 46 |
| 46 class _ProcessImpl extends NativeFieldWrapperClass1 implements Process { | 47 class _ProcessImpl extends NativeFieldWrapperClass1 implements Process { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 throw new ArgumentError( | 241 throw new ArgumentError( |
| 241 "Argument 'signal' must be a ProcessSignal"); | 242 "Argument 'signal' must be a ProcessSignal"); |
| 242 } | 243 } |
| 243 assert(_started); | 244 assert(_started); |
| 244 if (_ended) return false; | 245 if (_ended) return false; |
| 245 return _kill(this, signal._signalNumber); | 246 return _kill(this, signal._signalNumber); |
| 246 } | 247 } |
| 247 | 248 |
| 248 bool _kill(Process p, int signal) native "Process_Kill"; | 249 bool _kill(Process p, int signal) native "Process_Kill"; |
| 249 | 250 |
| 251 int get pid => _ProcessUtils._pid(this); | |
| 252 | |
| 250 String _path; | 253 String _path; |
| 251 List<String> _arguments; | 254 List<String> _arguments; |
| 252 String _workingDirectory; | 255 String _workingDirectory; |
| 253 List<String> _environment; | 256 List<String> _environment; |
| 254 // Private methods of Socket are used by _in, _out, and _err. | 257 // Private methods of Socket are used by _in, _out, and _err. |
| 255 _StdSink _stdin; | 258 _StdSink _stdin; |
| 256 _StdStream _stdout; | 259 _StdStream _stdout; |
| 257 _StdStream _stderr; | 260 _StdStream _stderr; |
| 258 Socket _exitHandler; | 261 Socket _exitHandler; |
| 259 bool _ended; | 262 bool _ended; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 284 stderrEncoding = options.stderrEncoding; | 287 stderrEncoding = options.stderrEncoding; |
| 285 if (stderrEncoding is !Encoding) { | 288 if (stderrEncoding is !Encoding) { |
| 286 throw new ArgumentError( | 289 throw new ArgumentError( |
| 287 'stderrEncoding option is not an encoding: $stderrEncoding'); | 290 'stderrEncoding option is not an encoding: $stderrEncoding'); |
| 288 } | 291 } |
| 289 } | 292 } |
| 290 } | 293 } |
| 291 | 294 |
| 292 // Start the underlying process. | 295 // Start the underlying process. |
| 293 return Process.start(path, arguments, options).then((Process p) { | 296 return Process.start(path, arguments, options).then((Process p) { |
| 297 int pid = p.pid; | |
| 298 | |
| 294 // Make sure the process stdin is closed. | 299 // Make sure the process stdin is closed. |
| 295 p.stdin.close(); | 300 p.stdin.close(); |
| 296 | 301 |
| 297 // Setup stdout handling. | 302 // Setup stdout handling. |
| 298 Future<StringBuffer> stdout = p.stdout | 303 Future<StringBuffer> stdout = p.stdout |
| 299 .transform(new StringDecoder(stdoutEncoding)) | 304 .transform(new StringDecoder(stdoutEncoding)) |
| 300 .fold( | 305 .fold( |
| 301 new StringBuffer(), | 306 new StringBuffer(), |
| 302 (buf, data) { | 307 (buf, data) { |
| 303 buf.write(data); | 308 buf.write(data); |
| 304 return buf; | 309 return buf; |
| 305 }); | 310 }); |
| 306 | 311 |
| 307 Future<StringBuffer> stderr = p.stderr | 312 Future<StringBuffer> stderr = p.stderr |
| 308 .transform(new StringDecoder(stderrEncoding)) | 313 .transform(new StringDecoder(stderrEncoding)) |
| 309 .fold( | 314 .fold( |
| 310 new StringBuffer(), | 315 new StringBuffer(), |
| 311 (buf, data) { | 316 (buf, data) { |
| 312 buf.write(data); | 317 buf.write(data); |
| 313 return buf; | 318 return buf; |
| 314 }); | 319 }); |
| 315 | 320 |
| 316 return Future.wait([p.exitCode, stdout, stderr]).then((result) { | 321 return Future.wait([p.exitCode, stdout, stderr]).then((result) { |
| 317 return new _ProcessResult(result[0], | 322 return new _ProcessResult(pid, |
| 323 result[0], | |
| 318 result[1].toString(), | 324 result[1].toString(), |
| 319 result[2].toString()); | 325 result[2].toString()); |
| 320 }); | 326 }); |
| 321 }); | 327 }); |
| 322 } | 328 } |
| 323 | 329 |
| 324 | 330 |
| 325 class _ProcessResult implements ProcessResult { | 331 class _ProcessResult implements ProcessResult { |
| 326 const _ProcessResult(int this.exitCode, | 332 const _ProcessResult(int this.pid, |
|
Anders Johnsen
2013/04/17 09:13:06
I'm not sure it makes sense to get the pid of an a
Søren Gjesse
2013/04/17 10:15:12
Not sure either, but sometimes processes write fil
| |
| 333 int this.exitCode, | |
| 327 String this.stdout, | 334 String this.stdout, |
| 328 String this.stderr); | 335 String this.stderr); |
| 329 | 336 |
| 337 final int pid; | |
| 330 final int exitCode; | 338 final int exitCode; |
| 331 final String stdout; | 339 final String stdout; |
| 332 final String stderr; | 340 final String stderr; |
| 333 } | 341 } |
| OLD | NEW |