Repository: flutter
Issue: flutter run (when spawned from external script) crashes when its stdin is written to
Labels: c: crash,tool,has reproducible steps,P2,found in release: 3.0,found in release: 3.1,team-tool,triaged-tool

<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.dev/
      * https://api.flutter.dev/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a bug or if our documentation doesn't have an answer
     to what you're looking for, then fill our the template below. Please read
     our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
-->

## Steps to Reproduce

<!-- Please tell us exactly how to reproduce the problem you are running into. -->
description: I was attempting to induce a hot reload from a build/test script written in rust,
this example illustrates the attempted use of q hotkey after flutter is running

1. install rust toolchain (https://www.rust-lang.org/tools/install)
2. ```cargo new flutter_stdin```
3. paste https://gist.github.com/smokytheangel0/c2f4b97ab0037a1e1357b9848dd17274 into flutter_stdin/src/main.rs
4. ```cargo build``` in flutter_stdin
5. ```flutter create stdin_test``` in ../
6. ```cp flutter_stdin/target/debug/flutter_stdin stdin_test```
7. ```./flutter_stdin``` in stdin_test

## Logs

<!--
      Include the full logs of the commands you are running between the lines
      with the backticks below. If you are running any "flutter" commands,
      please include the output of running them with "--verbose"; for example,
      the output of running "flutter --verbose create foo".
-->

```
Unhandled exception:
FileSystemException: writeFrom failed, path = '' (OS Error: Broken pipe, errno = 32)
#0      _RandomAccessFile.writeFromSync (dart:io/file_impl.dart:881:7)
#1      _StdConsumer.addStream.<anonymous closure> (dart:io/stdio.dart:312:15)
#2      _rootRunUnary (dart:async/zone.dart:1138:13)
#3      _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#4      _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
#5      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#6      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:266:7)
#7      _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:773:19)
#8      _StreamController._add (dart:async/stream_controller.dart:649:7)
#9      _StreamController.add (dart:async/stream_controller.dart:595:5)
#10     _StreamSinkImpl.add (dart:io/io_sink.dart:158:17)
#11     _IOSinkImpl.write (dart:io/io_sink.dart:291:5)
#12     _StdSink.write (dart:io/stdio.dart:341:11)
#13     Stdio._stdioWrite.<anonymous closure> (package:flutter_tools/src/base/io.dart:276:12)
#14     asyncGuard.<anonymous closure> (package:flutter_tools/src/base/async_guard.dart:111:32)
#15     _rootRun (dart:async/zone.dart:1126:13)
#16     _CustomZone.run (dart:async/zone.dart:1023:19)
#17     _runZoned (dart:async/zone.dart:1518:10)
#18     runZoned (dart:async/zone.dart:1502:12)
#19     asyncGuard (package:flutter_tools/src/base/async_guard.dart:109:3)
#20     Stdio._stdioWrite (package:flutter_tools/src/base/io.dart:275:5)
#21     Stdio.stdoutWrite (package:flutter_tools/src/base/io.dart:269:9)
#22     StdoutLogger.writeToStdOut (package:flutter_tools/src/base/logger.dart:270:48)
#23     StdoutLogger.printStatus (package:flutter_tools/src/base/logger.dart:265:5)
#24     printStatus (package:flutter_tools/src/globals.dart:128:10)
#25     TerminalHandler._commonTerminalInputHandler (package:flutter_tools/src/resident_runner.dart:1161:5)
#26     TerminalHandler.processTerminalInput (package:flutter_tools/src/resident_runner.dart:1303:13)
#27     _rootRunUnary (dart:async/zone.dart:1134:38)
#28     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#29     _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
#30     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#31     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:266:7)
#32     _SyncBroadcastStreamController._sendData (dart:async/broadcast_stream_controller.dart:377:20)
#33     _BroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:252:5)
#34     _AsBroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:476:11)
#35     _rootRunUnary (dart:async/zone.dart:1134:38)
#36     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#37     _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
#38     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#39     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:266:7)
#40     _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:70:11)
#41     _EventSinkWrapper.add (dart:async/stream_transformers.dart:17:11)
#42     _StringAdapterSink.add (dart:convert/string_conversion.dart:238:11)
#43     _StringAdapterSink.addSlice (dart:convert/string_conversion.dart:243:7)
#44     _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:314:20)
#45     _ErrorHandlingAsciiDecoderSink.addSlice (dart:convert/ascii.dart:254:17)
#46     _ErrorHandlingAsciiDecoderSink.add (dart:convert/ascii.dart:240:5)
#47     _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:74:18)
#48     _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:122:24)
#49     _rootRunUnary (dart:async/zone.dart:1134:38)
#50     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#51     _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
#52     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#53     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:266:7)
#54     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:773:19)
#55     _StreamController._add (dart:async/stream_controller.dart:649:7)
#56     _StreamController.add (dart:async/stream_controller.dart:595:5)
#57     _Socket._onData (dart:io-patch/socket_patch.dart:1878:41)
#58     _rootRunUnary (dart:async/zone.dart:1138:13)
#59     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#60     _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
#61     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#62     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:266:7)
#63     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:773:19)
#64     _StreamController._add (dart:async/stream_controller.dart:649:7)
#65     _StreamController.add (dart:async/stream_controller.dart:595:5)
#66     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1423:33)
#67     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:927:14)
#68     _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#69     _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
#70     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#71     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:169:5)

```

<!-- If possible, paste the output of running `flutter doctor -v` here. -->

```
[✓] Flutter (Channel master, v1.15.4-pre.201, on Linux, locale en_US.UTF-8)
    • Flutter version 1.15.4-pre.201 at /home/j0/flutter
    • Framework revision 52a5311924 (5 days ago), 2020-02-27 10:41:08 -0800
    • Engine revision 060a7733a6
    • Dart version 2.8.0 (build 2.8.0-dev.10.0 4189237330)

[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /home/j0/Android/Sdk
    • Android NDK location not configured (optional; useful for native profiling
      support)
    • Platform android-29, build-tools 29.0.3
    • ANDROID_HOME = /home/j0/Android/Sdk
    • Java binary at: /home/j0/Downloads/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_212-release-1586-b4-5784211)
    ✗ Android license status unknown.
      Try re-installing or updating your Android SDK Manager.
      See https://developer.android.com/studio/#downloads or visit
      https://flutter.dev/setup/#android-setup for detailed instructions.

[!] Android Studio (version 3.6)
    • Android Studio at /home/j0/Downloads/android-studio
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build
      1.8.0_212-release-1586-b4-5784211)

[✓] VS Code (version 1.41.1)
    • VS Code at /usr/share/code
    • Flutter extension version 3.8.1

[✓] Connected device (1 available)
    • Nexus 6P • 84B7N15A07006474 • android-arm64 • Android 8.1.0 (API 27)

! Doctor found issues in 2 categories.

```