Description
This issue was originally filed by @butlermatt
If using Process.start() to launch an interactive process, you cannot retrieve any of the data from Process.stdout until after the process has terminated in some way. As an example see the following code:
(Assumes linux with BSD games installed)
=== Code ===
import 'dart:io';
void main() {
var userIn = new StringInputStream(stdin);
var p = Process.start('/usr/games/adventure', []);
p.onError = (e) {
print('Error: $e');
exit(1);
};
p.onStart = () {
p.stdout.onData = () {
var str = new String.fromCharCodes(p.stdout.read());
print(str);
};
var errFromProcess = new StringInputStream(p.stderr);
errFromProcess.onLine = () {
var str = errFromProcess.readLine();
print(str);
};
userIn.onLine = () {
var str = userIn.readLine().trim();
print('Sending: $str');
p.stdin.writeString('$str\n');
};
};
// p.onExit = (code) {
// p.close();
// exit(code);
// };
}
=== end Code ===
Now if you run this application, nothing will appear. In command however type in:
no
quit
yes
Each on their own line. no will respond to "do you wish instructions?"
quit will request the process to exit
and yes will confirm the request. Once you type 'yes' then the actual output of the process is THEN sent to the p.stdout.onData() function. However if I uncomment out the p.onExit(); then that data is never received. It only appears to flush the stream if it is closed by the process not by the application.