When working in the python repl I often need to edit multiline code.
So I use import os then os.system("notepad npad.py")
In clojure I first run (use '[clojure.java.shell :only [sh]])
Then I run (sh "notepad" "jpad.clj")
This starts notepad but not in a useful way because the clojure repl now hangs. In other words, until I close notepad I cannot enter code in the repl and I want to keep both open.
I know I can easily open notepad without clojure so it is no big deal. However, is there a way for clojure to start an external process without hanging?
future is a convenient way to leave work running in the background, and it is easy to check up on the process later.
user> (def notepad-process (future (sh "emacs" "jpad.clj")))
#'user/notepad-process
Edit the file for a while, then check on the process later if you want its exit code:
user> @notepad-process
{:exit 0, :out "", :err ""}
It sounds like you want sh to return immediately instead of waiting for notepad's exit code. How about writing a sh! macro or somesuch that runs the original sh command on a new Thread? If you're only using this as a convenience in the REPL, it would be entirely unproblematic.
EDIT
Arthur's answer is better and more Clojurian - go with that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With