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 import 'dart:io'; | 5 import 'dart:io'; |
6 import 'dart:isolate'; | 6 import 'dart:isolate'; |
7 | 7 |
8 main() { | 8 main() { |
9 // Open a port to make the script hang. | 9 // Open a port to make the script hang. |
10 var port = new ReceivePort(); | 10 var port = new ReceivePort(); |
11 // Start sub-process when receiving data. | 11 // Start sub-process when receiving data. |
12 var subscription; | 12 var subscription; |
13 subscription = stdin.listen((data) { | 13 subscription = stdin.listen((data) { |
14 Process.start(Platform.executable, | 14 Process |
15 [Platform.script.toFilePath()]).then((p) { | 15 .start(Platform.executable, [Platform.script.toFilePath()]).then((p) { |
16 p.stdout.listen((_) { }); | 16 p.stdout.listen((_) {}); |
17 p.stderr.listen((_) { }); | 17 p.stderr.listen((_) {}); |
18 // When receiving data again, kill sub-process and exit. | 18 // When receiving data again, kill sub-process and exit. |
19 subscription.onData((data) { | 19 subscription.onData((data) { |
20 // If a SIGTERM is sent before the child-process's main is invoked, | 20 // If a SIGTERM is sent before the child-process's main is invoked, |
21 // there is a change that the SIGTERM is ignore on Mac OS X. Use | 21 // there is a change that the SIGTERM is ignore on Mac OS X. Use |
22 // SIGKILL to get around the issue. | 22 // SIGKILL to get around the issue. |
23 p.kill(ProcessSignal.SIGKILL); | 23 p.kill(ProcessSignal.SIGKILL); |
24 p.exitCode.then((_) => exit(0)); | 24 p.exitCode.then((_) => exit(0)); |
25 }); | 25 }); |
26 // Close stdout. If handles are incorrectly inherited this will | 26 // Close stdout. If handles are incorrectly inherited this will |
27 // not actually close stdout and the test will hang. | 27 // not actually close stdout and the test will hang. |
28 stdout.close(); | 28 stdout.close(); |
29 }); | 29 }); |
30 }); | 30 }); |
31 } | 31 } |
OLD | NEW |