I have a REPL (read-eval-print-loop) for the Clojure programming language listening on a network socket. I can send it code over the network and the code will be evaluated and the answer sent back to me. I'm using the
netcat utility to send the code
# send the contents of code.txt to port 5678 on somemachine $ netcat somemachine 5678 <code.txt
My problem is that I don't want to use the Loop capability of this REPL. On my end, I want to issue a one-shot command, receive and show the answer on stdout, then exit my command (the REPL on the remote machine should stay up). The below example works except
netcat doesn't exit and I remain connected to the REPL indefinitely.
$ cat code.txt (doseq [x (range 0 10)] (println (* x x))) $ netcat somemachine 5678 <code.txt user=> 0 1 4 9 16 25 36 49 64 81 nil user=>
We can see that the REPL's prompt ("user=> ") is displayed twice: once before the code is evaluated and once after. It seems like the key to getting what I want is chaining something on to the end of my command that watches and waits until the prompt is shown a second time then kills
When running this manually in a bash terminal, I could instead just press Ctrl-C after I see the second prompt, but the purpose of this is to be used in an extension to the TextMate editor.