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 |
11 patch class _WindowsCodePageEncoder { | 11 patch class _WindowsCodePageEncoder { |
12 /* patch */ static List<int> _encodeString(String string) | 12 /* patch */ static List<int> _encodeString(String string) |
13 native "StringToSystemEncoding"; | 13 native "StringToSystemEncoding"; |
14 } | 14 } |
15 | 15 |
16 | 16 |
17 patch class Process { | 17 patch class Process { |
18 /* patch */ static Future<Process> start( | 18 /* patch */ static Future<Process> start( |
19 String executable, | 19 String executable, |
20 List<String> arguments, | 20 List<String> arguments, |
21 {String workingDirectory, | 21 {String workingDirectory, |
22 Map<String, String> environment, | 22 Map<String, String> environment, |
23 bool runInShell}) { | 23 bool includeParentEnvironment: true, |
| 24 bool runInShell: false}) { |
24 _ProcessImpl process = new _ProcessImpl(executable, | 25 _ProcessImpl process = new _ProcessImpl(executable, |
25 arguments, | 26 arguments, |
26 workingDirectory, | 27 workingDirectory, |
27 environment, | 28 environment, |
| 29 includeParentEnvironment, |
28 runInShell); | 30 runInShell); |
29 return process._start(); | 31 return process._start(); |
30 } | 32 } |
31 | 33 |
32 /* patch */ static Future<ProcessResult> run( | 34 /* patch */ static Future<ProcessResult> run( |
33 String executable, | 35 String executable, |
34 List<String> arguments, | 36 List<String> arguments, |
35 {String workingDirectory, | 37 {String workingDirectory, |
36 Map<String, String> environment, | 38 Map<String, String> environment, |
37 bool runInShell, | 39 bool includeParentEnvironment: true, |
| 40 bool runInShell: false, |
38 Encoding stdoutEncoding: Encoding.SYSTEM, | 41 Encoding stdoutEncoding: Encoding.SYSTEM, |
39 Encoding stderrEncoding: Encoding.SYSTEM}) { | 42 Encoding stderrEncoding: Encoding.SYSTEM}) { |
40 return _runNonInteractiveProcess(executable, | 43 return _runNonInteractiveProcess(executable, |
41 arguments, | 44 arguments, |
42 workingDirectory, | 45 workingDirectory, |
43 environment, | 46 environment, |
| 47 includeParentEnvironment, |
44 runInShell, | 48 runInShell, |
45 stdoutEncoding, | 49 stdoutEncoding, |
46 stderrEncoding); | 50 stderrEncoding); |
47 } | 51 } |
48 } | 52 } |
49 | 53 |
50 | 54 |
51 patch class _ProcessUtils { | 55 patch class _ProcessUtils { |
52 /* patch */ static void _exit(int status) native "Process_Exit"; | 56 /* patch */ static void _exit(int status) native "Process_Exit"; |
53 /* patch */ static void _setExitCode(int status) | 57 /* patch */ static void _setExitCode(int status) |
54 native "Process_SetExitCode"; | 58 native "Process_SetExitCode"; |
55 /* patch */ static void _sleep(int millis) native "Process_Sleep"; | 59 /* patch */ static void _sleep(int millis) native "Process_Sleep"; |
56 /* patch */ static int _pid(Process process) native "Process_Pid"; | 60 /* patch */ static int _pid(Process process) native "Process_Pid"; |
57 } | 61 } |
58 | 62 |
59 | 63 |
60 class _ProcessStartStatus { | 64 class _ProcessStartStatus { |
61 int _errorCode; // Set to OS error code if process start failed. | 65 int _errorCode; // Set to OS error code if process start failed. |
62 String _errorMessage; // Set to OS error message if process start failed. | 66 String _errorMessage; // Set to OS error message if process start failed. |
63 } | 67 } |
64 | 68 |
65 | 69 |
66 class _ProcessImpl extends NativeFieldWrapperClass1 implements Process { | 70 class _ProcessImpl extends NativeFieldWrapperClass1 implements Process { |
67 _ProcessImpl(String path, | 71 _ProcessImpl(String path, |
68 List<String> arguments, | 72 List<String> arguments, |
69 String this._workingDirectory, | 73 String this._workingDirectory, |
70 Map<String, String> environment, | 74 Map<String, String> environment, |
| 75 bool includeParentEnvironment, |
71 bool runInShell) { | 76 bool runInShell) { |
72 runInShell = identical(runInShell, true); | 77 runInShell = identical(runInShell, true); |
73 if (runInShell) { | 78 if (runInShell) { |
74 arguments = _getShellArguments(path, arguments); | 79 arguments = _getShellArguments(path, arguments); |
75 path = _getShellCommand(); | 80 path = _getShellCommand(); |
76 } | 81 } |
77 | 82 |
78 if (path is !String) { | 83 if (path is !String) { |
79 throw new ArgumentError("Path is not a String: $path"); | 84 throw new ArgumentError("Path is not a String: $path"); |
80 } | 85 } |
(...skipping 13 matching lines...) Expand all Loading... |
94 if (Platform.operatingSystem == 'windows') { | 99 if (Platform.operatingSystem == 'windows') { |
95 _arguments[i] = _windowsArgumentEscape(_arguments[i]); | 100 _arguments[i] = _windowsArgumentEscape(_arguments[i]); |
96 } | 101 } |
97 } | 102 } |
98 | 103 |
99 if (_workingDirectory != null && _workingDirectory is !String) { | 104 if (_workingDirectory != null && _workingDirectory is !String) { |
100 throw new ArgumentError( | 105 throw new ArgumentError( |
101 "WorkingDirectory is not a String: $_workingDirectory"); | 106 "WorkingDirectory is not a String: $_workingDirectory"); |
102 } | 107 } |
103 | 108 |
104 if (environment != null) { | 109 _environment = []; |
105 var env = environment; | 110 if (environment == null) { |
106 if (env is !Map) { | 111 environment = {}; |
107 throw new ArgumentError("Environment is not a map: $env"); | 112 } |
| 113 if (environment is !Map) { |
| 114 throw new ArgumentError("Environment is not a map: $environment"); |
| 115 } |
| 116 if (identical(true, includeParentEnvironment)) { |
| 117 environment = Platform.environment..addAll(environment); |
| 118 } |
| 119 environment.forEach((key, value) { |
| 120 if (key is !String || value is !String) { |
| 121 throw new ArgumentError( |
| 122 "Environment key or value is not a string: ($key, $value)"); |
108 } | 123 } |
109 _environment = []; | 124 _environment.add('$key=$value'); |
110 env.forEach((key, value) { | 125 }); |
111 if (key is !String || value is !String) { | |
112 throw new ArgumentError( | |
113 "Environment key or value is not a string: ($key, $value)"); | |
114 } | |
115 _environment.add('$key=$value'); | |
116 }); | |
117 } | |
118 | 126 |
119 // stdin going to process. | 127 // stdin going to process. |
120 _stdin = new _StdSink(new _Socket._writePipe()); | 128 _stdin = new _StdSink(new _Socket._writePipe()); |
121 // stdout coming from process. | 129 // stdout coming from process. |
122 _stdout = new _StdStream(new _Socket._readPipe()); | 130 _stdout = new _StdStream(new _Socket._readPipe()); |
123 // stderr coming from process. | 131 // stderr coming from process. |
124 _stderr = new _StdStream(new _Socket._readPipe()); | 132 _stderr = new _StdStream(new _Socket._readPipe()); |
125 _exitHandler = new _Socket._readPipe(); | 133 _exitHandler = new _Socket._readPipe(); |
126 _ended = false; | 134 _ended = false; |
127 _started = false; | 135 _started = false; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 | 332 |
325 | 333 |
326 // _NonInteractiveProcess is a wrapper around an interactive process | 334 // _NonInteractiveProcess is a wrapper around an interactive process |
327 // that buffers output so it can be delivered when the process exits. | 335 // that buffers output so it can be delivered when the process exits. |
328 // _NonInteractiveProcess is used to implement the Process.run | 336 // _NonInteractiveProcess is used to implement the Process.run |
329 // method. | 337 // method. |
330 Future<ProcessResult> _runNonInteractiveProcess(String path, | 338 Future<ProcessResult> _runNonInteractiveProcess(String path, |
331 List<String> arguments, | 339 List<String> arguments, |
332 String workingDirectory, | 340 String workingDirectory, |
333 Map<String, String> environment, | 341 Map<String, String> environment, |
| 342 bool includeParentEnvironment, |
334 bool runInShell, | 343 bool runInShell, |
335 Encoding stdoutEncoding, | 344 Encoding stdoutEncoding, |
336 Encoding stderrEncoding) { | 345 Encoding stderrEncoding) { |
337 // Start the underlying process. | 346 // Start the underlying process. |
338 return Process.start(path, | 347 return Process.start(path, |
339 arguments, | 348 arguments, |
340 workingDirectory: workingDirectory, | 349 workingDirectory: workingDirectory, |
341 environment: environment, | 350 environment: environment, |
| 351 includeParentEnvironment: includeParentEnvironment, |
342 runInShell: runInShell).then((Process p) { | 352 runInShell: runInShell).then((Process p) { |
343 int pid = p.pid; | 353 int pid = p.pid; |
344 | 354 |
345 // Make sure the process stdin is closed. | 355 // Make sure the process stdin is closed. |
346 p.stdin.close(); | 356 p.stdin.close(); |
347 | 357 |
348 // Setup stdout and stderr handling. | 358 // Setup stdout and stderr handling. |
349 Future foldStream(Stream<List<int>> stream, Encoding encoding) { | 359 Future foldStream(Stream<List<int>> stream, Encoding encoding) { |
350 if (encoding == null) { | 360 if (encoding == null) { |
351 return stream | 361 return stream |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 const _ProcessResult(int this.pid, | 393 const _ProcessResult(int this.pid, |
384 int this.exitCode, | 394 int this.exitCode, |
385 this.stdout, | 395 this.stdout, |
386 this.stderr); | 396 this.stderr); |
387 | 397 |
388 final int pid; | 398 final int pid; |
389 final int exitCode; | 399 final int exitCode; |
390 final stdout; | 400 final stdout; |
391 final stderr; | 401 final stderr; |
392 } | 402 } |
OLD | NEW |