Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/executable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Future<int> runExecutable(Entrypoint entrypoint, String package,
// that prevents pub from also writing to the output streams.
process.stderr.listen(stderr.add);
process.stdout.listen(stdout.add);
stdin.listen(process.stdin.add);
stdin.listen(process.stdin.add, onDone: process.stdin.close);

// Work around dart-lang/sdk#25348.
process.stdin.done.catchError((_) {});
Expand Down
57 changes: 42 additions & 15 deletions test/run/app_can_read_from_stdin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@
import '../descriptor.dart' as d;
import '../test_pub.dart';

const SCRIPT = """
import 'dart:io';

main() {
print("started");
var line1 = stdin.readLineSync();
print("between");
var line2 = stdin.readLineSync();
print(line1);
print(line2);
}
""";

main() {
integration('the spawned application can read from stdin', () {
integration('the spawned application can read line-by-line from stdin', () {
d.dir(appPath, [
d.appPubspec(),
d.dir("bin", [
d.file("script.dart", SCRIPT)
d.file("script.dart", """
import 'dart:io';

main() {
print("started");
var line1 = stdin.readLineSync();
print("between");
var line2 = stdin.readLineSync();
print(line1);
print(line2);
}
""")
])
]).create();

Expand All @@ -38,4 +36,33 @@ main() {
pub.stdout.expect("second");
pub.shouldExit(0);
});

integration('the spawned application can read streamed from stdin', () {
d.dir(appPath, [
d.appPubspec(),
d.dir("bin", [
d.file("script.dart", """
import 'dart:io';

main() {
print("started");
stdin.listen(stdout.add);
}
""")
])
]).create();

pubGet();
var pub = pubRun(args: ["bin/script"]);

pub.stdout.expect("started");
pub.writeLine("first");
pub.stdout.expect("first");
pub.writeLine("second");
pub.stdout.expect("second");
pub.writeLine("third");
pub.stdout.expect("third");
pub.closeStdin();
pub.shouldExit(0);
});
}