Need Help: How do I send commands to a Process that takes commands from stdin?

79 views
Skip to first unread message

XulChris

unread,
Aug 10, 2012, 7:27:57 PM8/10/12
to mi...@dartlang.org
Hi, I'm trying to write a dart application that can talk to a standalone process on my server, I need to be able to both read and write to that process.

The dartlang web site shows a nice example of how to get output from a process here:

However, this example does not show how to write data to the process' stdin.

Here is my broken, non-working code:
void main() {
  var p = Process.start('/usr/local/bin/stockfish', []);
  var stdoutStream = new StringInputStream(p.stdout);

  stdoutStream.onLine = () => print(stdoutStream.readLine());
  p.stdin.writeString("exit\n", Encoding.ASCII); // SocketIOException: writeList failed - invalid socket handle

  p.onExit = (exitCode) {
    print('exit code: $exitCode');
    p.close();
  };
}

Please help. Am I doing this wrong? How do I send a command to a process that takes commands from stdin?

Kevin Kellogg

unread,
Aug 10, 2012, 11:17:24 PM8/10/12
to mi...@dartlang.org
It looks like you're writing to p.stdin before it's ready. Try:

p.onStart = ()  {
 // p.stdin is ready now.
};

Kevin

XulChris

unread,
Aug 11, 2012, 7:58:16 PM8/11/12
to mi...@dartlang.org
Yep, that was it! Thanks. :)
Reply all
Reply to author
Forward
0 new messages