3
我想寫一個飛鏢服務器應用程序,它將與一個接受輸入並給出輸出的應用程序進行通信,如unix工具bc。如何將數據發送到進程?
我可以讀取bc的輸出,但是我不能發送命令給bc。這裏是我的代碼:
#import('dart:io');
void main() {
var p = Process.start('bc', ["-i"]);
var stdoutStream = new StringInputStream(p.stdout);
stdoutStream.onLine =() => print(stdoutStream.readLine());
p.stdin.writeString("quit\n");
p.onExit = (exitCode) {
print('exit code: $exitCode');
p.close();
};
}
當我運行它,我得到以下錯誤:
Unhandled exception:
SocketIOException: writeList failed - invalid socket handle
0. Function: '[email protected]' url: 'dart:io' line:4808 col:48
1. Function: '[email protected][email protected]' url: 'dart:io' line:4993 col:70
2. Function: '[email protected]' url: 'dart:io' line:4969 col:29
3. Function: '[email protected]' url: 'dart:io' line:5197 col:3
4. Function: '::main' url: 'file:///var/www/html/example.dart' line:8 col:22
如果我註釋掉,我嘗試寫「退出\ n」行了,然後它運行我可以看到bc的輸出。
那麼如何讓我的程序將命令發送到我的服務器上的應用程序,如bc?