Reading/writing to stdio of running process/command does not work - reading blocks or is empty

,

The first query, "member(X, [1, 2, 3, 4, 5])." produces output without a newline, i.e. just X = 1 . So your readline waits indefinitely for the newline.