How to drop into a repl from within a Clojure command line application?












1















I'm writing a Clojure CLI application, and I would like to allow a command to be given to it which would drop people into the clojure.main REPL.



Does anyone know how I can go about doing that? My effort have not been fruitful.



EDIT:



My problem is made worse by the fact that my CLI takes piped input. Here's an example of what I'd like to work:



(ns playground.core
(:gen-class))

(defn -main
[& args]
(with-open [r (io/reader *in*)]
(doseq [line (line-seq r)]
(println line)))
;; Drop in repl after having read the input and printed its content)


I then call this as such:



cat ./somefile.txt | lein trampoline run









share|improve this question




















  • 1





    I don't think this is a duplicate because that question does not address the idea that the repl does not need to be the first consumer of input to the program and does not need to be started when the program starts.

    – Arthur Ulfeldt
    Nov 8 '18 at 19:24











  • Yes, my question is specifically trying to get an answer where the REPL is not the first thing to start. The program first starts, accepts inputs from in, do more things, and then it needs to transition into a REPL.

    – Didier A.
    Nov 11 '18 at 0:30











  • The CLI REPL operates over stdin and stdout, so does piping. Maybe you should use nREPL / socket REPL with pREPL and connect remotely? This keeps your stdin open for your file pipe but allows you to connect a REPL remotely. Alternatively you could read stdin then start a REPL as mentioned in other answers.

    – Olical
    Nov 14 '18 at 17:12











  • @Olical I could go that route, but the thing is, I'm done with stdin by the time I drop in the repl. But it seems something about stdin is causing the REPL to close right after it starts.

    – Didier A.
    Nov 14 '18 at 18:33
















1















I'm writing a Clojure CLI application, and I would like to allow a command to be given to it which would drop people into the clojure.main REPL.



Does anyone know how I can go about doing that? My effort have not been fruitful.



EDIT:



My problem is made worse by the fact that my CLI takes piped input. Here's an example of what I'd like to work:



(ns playground.core
(:gen-class))

(defn -main
[& args]
(with-open [r (io/reader *in*)]
(doseq [line (line-seq r)]
(println line)))
;; Drop in repl after having read the input and printed its content)


I then call this as such:



cat ./somefile.txt | lein trampoline run









share|improve this question




















  • 1





    I don't think this is a duplicate because that question does not address the idea that the repl does not need to be the first consumer of input to the program and does not need to be started when the program starts.

    – Arthur Ulfeldt
    Nov 8 '18 at 19:24











  • Yes, my question is specifically trying to get an answer where the REPL is not the first thing to start. The program first starts, accepts inputs from in, do more things, and then it needs to transition into a REPL.

    – Didier A.
    Nov 11 '18 at 0:30











  • The CLI REPL operates over stdin and stdout, so does piping. Maybe you should use nREPL / socket REPL with pREPL and connect remotely? This keeps your stdin open for your file pipe but allows you to connect a REPL remotely. Alternatively you could read stdin then start a REPL as mentioned in other answers.

    – Olical
    Nov 14 '18 at 17:12











  • @Olical I could go that route, but the thing is, I'm done with stdin by the time I drop in the repl. But it seems something about stdin is causing the REPL to close right after it starts.

    – Didier A.
    Nov 14 '18 at 18:33














1












1








1








I'm writing a Clojure CLI application, and I would like to allow a command to be given to it which would drop people into the clojure.main REPL.



Does anyone know how I can go about doing that? My effort have not been fruitful.



EDIT:



My problem is made worse by the fact that my CLI takes piped input. Here's an example of what I'd like to work:



(ns playground.core
(:gen-class))

(defn -main
[& args]
(with-open [r (io/reader *in*)]
(doseq [line (line-seq r)]
(println line)))
;; Drop in repl after having read the input and printed its content)


I then call this as such:



cat ./somefile.txt | lein trampoline run









share|improve this question
















I'm writing a Clojure CLI application, and I would like to allow a command to be given to it which would drop people into the clojure.main REPL.



Does anyone know how I can go about doing that? My effort have not been fruitful.



EDIT:



My problem is made worse by the fact that my CLI takes piped input. Here's an example of what I'd like to work:



(ns playground.core
(:gen-class))

(defn -main
[& args]
(with-open [r (io/reader *in*)]
(doseq [line (line-seq r)]
(println line)))
;; Drop in repl after having read the input and printed its content)


I then call this as such:



cat ./somefile.txt | lein trampoline run






clojure command-line-interface read-eval-print-loop






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 '18 at 10:44







Didier A.

















asked Nov 7 '18 at 8:34









Didier A.Didier A.

1,96822030




1,96822030








  • 1





    I don't think this is a duplicate because that question does not address the idea that the repl does not need to be the first consumer of input to the program and does not need to be started when the program starts.

    – Arthur Ulfeldt
    Nov 8 '18 at 19:24











  • Yes, my question is specifically trying to get an answer where the REPL is not the first thing to start. The program first starts, accepts inputs from in, do more things, and then it needs to transition into a REPL.

    – Didier A.
    Nov 11 '18 at 0:30











  • The CLI REPL operates over stdin and stdout, so does piping. Maybe you should use nREPL / socket REPL with pREPL and connect remotely? This keeps your stdin open for your file pipe but allows you to connect a REPL remotely. Alternatively you could read stdin then start a REPL as mentioned in other answers.

    – Olical
    Nov 14 '18 at 17:12











  • @Olical I could go that route, but the thing is, I'm done with stdin by the time I drop in the repl. But it seems something about stdin is causing the REPL to close right after it starts.

    – Didier A.
    Nov 14 '18 at 18:33














  • 1





    I don't think this is a duplicate because that question does not address the idea that the repl does not need to be the first consumer of input to the program and does not need to be started when the program starts.

    – Arthur Ulfeldt
    Nov 8 '18 at 19:24











  • Yes, my question is specifically trying to get an answer where the REPL is not the first thing to start. The program first starts, accepts inputs from in, do more things, and then it needs to transition into a REPL.

    – Didier A.
    Nov 11 '18 at 0:30











  • The CLI REPL operates over stdin and stdout, so does piping. Maybe you should use nREPL / socket REPL with pREPL and connect remotely? This keeps your stdin open for your file pipe but allows you to connect a REPL remotely. Alternatively you could read stdin then start a REPL as mentioned in other answers.

    – Olical
    Nov 14 '18 at 17:12











  • @Olical I could go that route, but the thing is, I'm done with stdin by the time I drop in the repl. But it seems something about stdin is causing the REPL to close right after it starts.

    – Didier A.
    Nov 14 '18 at 18:33








1




1





I don't think this is a duplicate because that question does not address the idea that the repl does not need to be the first consumer of input to the program and does not need to be started when the program starts.

– Arthur Ulfeldt
Nov 8 '18 at 19:24





I don't think this is a duplicate because that question does not address the idea that the repl does not need to be the first consumer of input to the program and does not need to be started when the program starts.

– Arthur Ulfeldt
Nov 8 '18 at 19:24













Yes, my question is specifically trying to get an answer where the REPL is not the first thing to start. The program first starts, accepts inputs from in, do more things, and then it needs to transition into a REPL.

– Didier A.
Nov 11 '18 at 0:30





Yes, my question is specifically trying to get an answer where the REPL is not the first thing to start. The program first starts, accepts inputs from in, do more things, and then it needs to transition into a REPL.

– Didier A.
Nov 11 '18 at 0:30













The CLI REPL operates over stdin and stdout, so does piping. Maybe you should use nREPL / socket REPL with pREPL and connect remotely? This keeps your stdin open for your file pipe but allows you to connect a REPL remotely. Alternatively you could read stdin then start a REPL as mentioned in other answers.

– Olical
Nov 14 '18 at 17:12





The CLI REPL operates over stdin and stdout, so does piping. Maybe you should use nREPL / socket REPL with pREPL and connect remotely? This keeps your stdin open for your file pipe but allows you to connect a REPL remotely. Alternatively you could read stdin then start a REPL as mentioned in other answers.

– Olical
Nov 14 '18 at 17:12













@Olical I could go that route, but the thing is, I'm done with stdin by the time I drop in the repl. But it seems something about stdin is causing the REPL to close right after it starts.

– Didier A.
Nov 14 '18 at 18:33





@Olical I could go that route, but the thing is, I'm done with stdin by the time I drop in the repl. But it seems something about stdin is causing the REPL to close right after it starts.

– Didier A.
Nov 14 '18 at 18:33












2 Answers
2






active

oldest

votes


















0














You can just call clojure.main/repl from your program and it will start listening to stdin and 'repl'ying to it ;-) at that point the repl will start



user> (clojure.main/repl)


then i type into the terminal (+ 1 2 3)



user=> 6
user=>


so i had a repl in a repl going there to simulate the case where the person using your program types the start repl command.



for making a human friendly repl experience the rebl-readline project adds a lot to calling clojure.main/repl:



(rebel-readline.core/with-line-reader
(rebel-readline.clojure.line-reader/create
(rebel-readline.clojure.service.local/create))
(clojure.main/repl
:prompt (fn ) ;; prompt is handled by line-reader
:read (rebel-readline.clojure.main/create-repl-read)))





Since your program has essentially two phases,


  1. read things from standard input forever or until standard input is permanently closed.

  2. once the program is dead or standard input is no longer available, whichever happens first read more from standard input.


You may want to (or perhaps you already have) a thing that breaks out of the with-open once some special line is sent. once this is received completely exit the line-seq and with-open. then start the repl so it can grab the input file-descriptor.




once you make the program get input to the repl, your piping issue can be solved in the enclosing shell command. cat takes a special argument - (just a dash nothing else with spaces on either side) that says "stop here and read from the keyboard until Crtl-d is pressed"

~ » cat a-file - | cat
hello im a line from a file
hello
hello


in this example it read a line from a file, passed it to the cat command (replace with your program), then it read the word hello from the keyboard and printed it as well (so you see it twice on the screen)






share|improve this answer


























  • I pipe input into my Clojure CLI. Such as cat somefile.txt | lein trampoline run. In that case, neither calling clojure.main/repl or using rebel-readline works. If I don't pipe input and just run lein trampoline run it does work though. Any idea how I can drop into the repl given I'm piping input?

    – Didier A.
    Nov 9 '18 at 10:37











  • I edited the question to make that more clear.

    – Didier A.
    Nov 9 '18 at 10:45











  • @DidierA. added the bit about getting around the piped input and some opinions on breaking it out of the read-line

    – Arthur Ulfeldt
    Nov 15 '18 at 17:33





















0














Maybe starting a headless REPL and have two separate steps might work for you?



Step 1



Launch a headless REPL, wait for it to start



$ lein repl :headless :host 0.0.0.0 :port 9000
nREPL server started on port 9000 on host 0.0.0.0 - nrepl://0.0.0.0:9000


Step 2



In another shell, send the commands to the REPL using your command:



$ cat test.txt 
(def hello "Hello world!")

$ cat test.txt | lein repl :connect 0.0.0.0:9000
Connecting to nREPL at 0.0.0.0:9000
REPL-y 0.3.7, nREPL 0.2.12
Clojure 1.8.0
OpenJDK 64-Bit Server VM 1.8.0_181-8u181-b13-1ubuntu0.18.04.1-b13
Docs: (doc function-name-here)
(find-doc "part-of-name-here")
Source: (source function-name-here)
Javadoc: (javadoc java-object-or-class-here)
Exit: Control+D or (exit) or (quit)
Results: Stored in vars *1, *2, *3, an exception in *e

pipetest.core=> (def hello "Hello world!")
#'pipetest.core/hello
pipetest.core=> Bye for now!


Step 3



You can connect to the REPL, continue after the state changes from the previous step, but now you can use it to interact.



$ lein repl :connect 0.0.0.0:9000
Connecting to nREPL at 0.0.0.0:9000
REPL-y 0.3.7, nREPL 0.2.12
Clojure 1.8.0
OpenJDK 64-Bit Server VM 1.8.0_181-8u181-b13-1ubuntu0.18.04.1-b13
Docs: (doc function-name-here)
(find-doc "part-of-name-here")
Source: (source function-name-here)
Javadoc: (javadoc java-object-or-class-here)
Exit: Control+D or (exit) or (quit)
Results: Stored in vars *1, *2, *3, an exception in *e

pipetest.core=> (str hello "!!!")
"Hello world!!!!"





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53185866%2fhow-to-drop-into-a-repl-from-within-a-clojure-command-line-application%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You can just call clojure.main/repl from your program and it will start listening to stdin and 'repl'ying to it ;-) at that point the repl will start



    user> (clojure.main/repl)


    then i type into the terminal (+ 1 2 3)



    user=> 6
    user=>


    so i had a repl in a repl going there to simulate the case where the person using your program types the start repl command.



    for making a human friendly repl experience the rebl-readline project adds a lot to calling clojure.main/repl:



    (rebel-readline.core/with-line-reader
    (rebel-readline.clojure.line-reader/create
    (rebel-readline.clojure.service.local/create))
    (clojure.main/repl
    :prompt (fn ) ;; prompt is handled by line-reader
    :read (rebel-readline.clojure.main/create-repl-read)))





    Since your program has essentially two phases,


    1. read things from standard input forever or until standard input is permanently closed.

    2. once the program is dead or standard input is no longer available, whichever happens first read more from standard input.


    You may want to (or perhaps you already have) a thing that breaks out of the with-open once some special line is sent. once this is received completely exit the line-seq and with-open. then start the repl so it can grab the input file-descriptor.




    once you make the program get input to the repl, your piping issue can be solved in the enclosing shell command. cat takes a special argument - (just a dash nothing else with spaces on either side) that says "stop here and read from the keyboard until Crtl-d is pressed"

    ~ » cat a-file - | cat
    hello im a line from a file
    hello
    hello


    in this example it read a line from a file, passed it to the cat command (replace with your program), then it read the word hello from the keyboard and printed it as well (so you see it twice on the screen)






    share|improve this answer


























    • I pipe input into my Clojure CLI. Such as cat somefile.txt | lein trampoline run. In that case, neither calling clojure.main/repl or using rebel-readline works. If I don't pipe input and just run lein trampoline run it does work though. Any idea how I can drop into the repl given I'm piping input?

      – Didier A.
      Nov 9 '18 at 10:37











    • I edited the question to make that more clear.

      – Didier A.
      Nov 9 '18 at 10:45











    • @DidierA. added the bit about getting around the piped input and some opinions on breaking it out of the read-line

      – Arthur Ulfeldt
      Nov 15 '18 at 17:33


















    0














    You can just call clojure.main/repl from your program and it will start listening to stdin and 'repl'ying to it ;-) at that point the repl will start



    user> (clojure.main/repl)


    then i type into the terminal (+ 1 2 3)



    user=> 6
    user=>


    so i had a repl in a repl going there to simulate the case where the person using your program types the start repl command.



    for making a human friendly repl experience the rebl-readline project adds a lot to calling clojure.main/repl:



    (rebel-readline.core/with-line-reader
    (rebel-readline.clojure.line-reader/create
    (rebel-readline.clojure.service.local/create))
    (clojure.main/repl
    :prompt (fn ) ;; prompt is handled by line-reader
    :read (rebel-readline.clojure.main/create-repl-read)))





    Since your program has essentially two phases,


    1. read things from standard input forever or until standard input is permanently closed.

    2. once the program is dead or standard input is no longer available, whichever happens first read more from standard input.


    You may want to (or perhaps you already have) a thing that breaks out of the with-open once some special line is sent. once this is received completely exit the line-seq and with-open. then start the repl so it can grab the input file-descriptor.




    once you make the program get input to the repl, your piping issue can be solved in the enclosing shell command. cat takes a special argument - (just a dash nothing else with spaces on either side) that says "stop here and read from the keyboard until Crtl-d is pressed"

    ~ » cat a-file - | cat
    hello im a line from a file
    hello
    hello


    in this example it read a line from a file, passed it to the cat command (replace with your program), then it read the word hello from the keyboard and printed it as well (so you see it twice on the screen)






    share|improve this answer


























    • I pipe input into my Clojure CLI. Such as cat somefile.txt | lein trampoline run. In that case, neither calling clojure.main/repl or using rebel-readline works. If I don't pipe input and just run lein trampoline run it does work though. Any idea how I can drop into the repl given I'm piping input?

      – Didier A.
      Nov 9 '18 at 10:37











    • I edited the question to make that more clear.

      – Didier A.
      Nov 9 '18 at 10:45











    • @DidierA. added the bit about getting around the piped input and some opinions on breaking it out of the read-line

      – Arthur Ulfeldt
      Nov 15 '18 at 17:33
















    0












    0








    0







    You can just call clojure.main/repl from your program and it will start listening to stdin and 'repl'ying to it ;-) at that point the repl will start



    user> (clojure.main/repl)


    then i type into the terminal (+ 1 2 3)



    user=> 6
    user=>


    so i had a repl in a repl going there to simulate the case where the person using your program types the start repl command.



    for making a human friendly repl experience the rebl-readline project adds a lot to calling clojure.main/repl:



    (rebel-readline.core/with-line-reader
    (rebel-readline.clojure.line-reader/create
    (rebel-readline.clojure.service.local/create))
    (clojure.main/repl
    :prompt (fn ) ;; prompt is handled by line-reader
    :read (rebel-readline.clojure.main/create-repl-read)))





    Since your program has essentially two phases,


    1. read things from standard input forever or until standard input is permanently closed.

    2. once the program is dead or standard input is no longer available, whichever happens first read more from standard input.


    You may want to (or perhaps you already have) a thing that breaks out of the with-open once some special line is sent. once this is received completely exit the line-seq and with-open. then start the repl so it can grab the input file-descriptor.




    once you make the program get input to the repl, your piping issue can be solved in the enclosing shell command. cat takes a special argument - (just a dash nothing else with spaces on either side) that says "stop here and read from the keyboard until Crtl-d is pressed"

    ~ » cat a-file - | cat
    hello im a line from a file
    hello
    hello


    in this example it read a line from a file, passed it to the cat command (replace with your program), then it read the word hello from the keyboard and printed it as well (so you see it twice on the screen)






    share|improve this answer















    You can just call clojure.main/repl from your program and it will start listening to stdin and 'repl'ying to it ;-) at that point the repl will start



    user> (clojure.main/repl)


    then i type into the terminal (+ 1 2 3)



    user=> 6
    user=>


    so i had a repl in a repl going there to simulate the case where the person using your program types the start repl command.



    for making a human friendly repl experience the rebl-readline project adds a lot to calling clojure.main/repl:



    (rebel-readline.core/with-line-reader
    (rebel-readline.clojure.line-reader/create
    (rebel-readline.clojure.service.local/create))
    (clojure.main/repl
    :prompt (fn ) ;; prompt is handled by line-reader
    :read (rebel-readline.clojure.main/create-repl-read)))





    Since your program has essentially two phases,


    1. read things from standard input forever or until standard input is permanently closed.

    2. once the program is dead or standard input is no longer available, whichever happens first read more from standard input.


    You may want to (or perhaps you already have) a thing that breaks out of the with-open once some special line is sent. once this is received completely exit the line-seq and with-open. then start the repl so it can grab the input file-descriptor.




    once you make the program get input to the repl, your piping issue can be solved in the enclosing shell command. cat takes a special argument - (just a dash nothing else with spaces on either side) that says "stop here and read from the keyboard until Crtl-d is pressed"

    ~ » cat a-file - | cat
    hello im a line from a file
    hello
    hello


    in this example it read a line from a file, passed it to the cat command (replace with your program), then it read the word hello from the keyboard and printed it as well (so you see it twice on the screen)







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 15 '18 at 17:32

























    answered Nov 8 '18 at 19:21









    Arthur UlfeldtArthur Ulfeldt

    73k20167251




    73k20167251













    • I pipe input into my Clojure CLI. Such as cat somefile.txt | lein trampoline run. In that case, neither calling clojure.main/repl or using rebel-readline works. If I don't pipe input and just run lein trampoline run it does work though. Any idea how I can drop into the repl given I'm piping input?

      – Didier A.
      Nov 9 '18 at 10:37











    • I edited the question to make that more clear.

      – Didier A.
      Nov 9 '18 at 10:45











    • @DidierA. added the bit about getting around the piped input and some opinions on breaking it out of the read-line

      – Arthur Ulfeldt
      Nov 15 '18 at 17:33





















    • I pipe input into my Clojure CLI. Such as cat somefile.txt | lein trampoline run. In that case, neither calling clojure.main/repl or using rebel-readline works. If I don't pipe input and just run lein trampoline run it does work though. Any idea how I can drop into the repl given I'm piping input?

      – Didier A.
      Nov 9 '18 at 10:37











    • I edited the question to make that more clear.

      – Didier A.
      Nov 9 '18 at 10:45











    • @DidierA. added the bit about getting around the piped input and some opinions on breaking it out of the read-line

      – Arthur Ulfeldt
      Nov 15 '18 at 17:33



















    I pipe input into my Clojure CLI. Such as cat somefile.txt | lein trampoline run. In that case, neither calling clojure.main/repl or using rebel-readline works. If I don't pipe input and just run lein trampoline run it does work though. Any idea how I can drop into the repl given I'm piping input?

    – Didier A.
    Nov 9 '18 at 10:37





    I pipe input into my Clojure CLI. Such as cat somefile.txt | lein trampoline run. In that case, neither calling clojure.main/repl or using rebel-readline works. If I don't pipe input and just run lein trampoline run it does work though. Any idea how I can drop into the repl given I'm piping input?

    – Didier A.
    Nov 9 '18 at 10:37













    I edited the question to make that more clear.

    – Didier A.
    Nov 9 '18 at 10:45





    I edited the question to make that more clear.

    – Didier A.
    Nov 9 '18 at 10:45













    @DidierA. added the bit about getting around the piped input and some opinions on breaking it out of the read-line

    – Arthur Ulfeldt
    Nov 15 '18 at 17:33







    @DidierA. added the bit about getting around the piped input and some opinions on breaking it out of the read-line

    – Arthur Ulfeldt
    Nov 15 '18 at 17:33















    0














    Maybe starting a headless REPL and have two separate steps might work for you?



    Step 1



    Launch a headless REPL, wait for it to start



    $ lein repl :headless :host 0.0.0.0 :port 9000
    nREPL server started on port 9000 on host 0.0.0.0 - nrepl://0.0.0.0:9000


    Step 2



    In another shell, send the commands to the REPL using your command:



    $ cat test.txt 
    (def hello "Hello world!")

    $ cat test.txt | lein repl :connect 0.0.0.0:9000
    Connecting to nREPL at 0.0.0.0:9000
    REPL-y 0.3.7, nREPL 0.2.12
    Clojure 1.8.0
    OpenJDK 64-Bit Server VM 1.8.0_181-8u181-b13-1ubuntu0.18.04.1-b13
    Docs: (doc function-name-here)
    (find-doc "part-of-name-here")
    Source: (source function-name-here)
    Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
    Results: Stored in vars *1, *2, *3, an exception in *e

    pipetest.core=> (def hello "Hello world!")
    #'pipetest.core/hello
    pipetest.core=> Bye for now!


    Step 3



    You can connect to the REPL, continue after the state changes from the previous step, but now you can use it to interact.



    $ lein repl :connect 0.0.0.0:9000
    Connecting to nREPL at 0.0.0.0:9000
    REPL-y 0.3.7, nREPL 0.2.12
    Clojure 1.8.0
    OpenJDK 64-Bit Server VM 1.8.0_181-8u181-b13-1ubuntu0.18.04.1-b13
    Docs: (doc function-name-here)
    (find-doc "part-of-name-here")
    Source: (source function-name-here)
    Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
    Results: Stored in vars *1, *2, *3, an exception in *e

    pipetest.core=> (str hello "!!!")
    "Hello world!!!!"





    share|improve this answer




























      0














      Maybe starting a headless REPL and have two separate steps might work for you?



      Step 1



      Launch a headless REPL, wait for it to start



      $ lein repl :headless :host 0.0.0.0 :port 9000
      nREPL server started on port 9000 on host 0.0.0.0 - nrepl://0.0.0.0:9000


      Step 2



      In another shell, send the commands to the REPL using your command:



      $ cat test.txt 
      (def hello "Hello world!")

      $ cat test.txt | lein repl :connect 0.0.0.0:9000
      Connecting to nREPL at 0.0.0.0:9000
      REPL-y 0.3.7, nREPL 0.2.12
      Clojure 1.8.0
      OpenJDK 64-Bit Server VM 1.8.0_181-8u181-b13-1ubuntu0.18.04.1-b13
      Docs: (doc function-name-here)
      (find-doc "part-of-name-here")
      Source: (source function-name-here)
      Javadoc: (javadoc java-object-or-class-here)
      Exit: Control+D or (exit) or (quit)
      Results: Stored in vars *1, *2, *3, an exception in *e

      pipetest.core=> (def hello "Hello world!")
      #'pipetest.core/hello
      pipetest.core=> Bye for now!


      Step 3



      You can connect to the REPL, continue after the state changes from the previous step, but now you can use it to interact.



      $ lein repl :connect 0.0.0.0:9000
      Connecting to nREPL at 0.0.0.0:9000
      REPL-y 0.3.7, nREPL 0.2.12
      Clojure 1.8.0
      OpenJDK 64-Bit Server VM 1.8.0_181-8u181-b13-1ubuntu0.18.04.1-b13
      Docs: (doc function-name-here)
      (find-doc "part-of-name-here")
      Source: (source function-name-here)
      Javadoc: (javadoc java-object-or-class-here)
      Exit: Control+D or (exit) or (quit)
      Results: Stored in vars *1, *2, *3, an exception in *e

      pipetest.core=> (str hello "!!!")
      "Hello world!!!!"





      share|improve this answer


























        0












        0








        0







        Maybe starting a headless REPL and have two separate steps might work for you?



        Step 1



        Launch a headless REPL, wait for it to start



        $ lein repl :headless :host 0.0.0.0 :port 9000
        nREPL server started on port 9000 on host 0.0.0.0 - nrepl://0.0.0.0:9000


        Step 2



        In another shell, send the commands to the REPL using your command:



        $ cat test.txt 
        (def hello "Hello world!")

        $ cat test.txt | lein repl :connect 0.0.0.0:9000
        Connecting to nREPL at 0.0.0.0:9000
        REPL-y 0.3.7, nREPL 0.2.12
        Clojure 1.8.0
        OpenJDK 64-Bit Server VM 1.8.0_181-8u181-b13-1ubuntu0.18.04.1-b13
        Docs: (doc function-name-here)
        (find-doc "part-of-name-here")
        Source: (source function-name-here)
        Javadoc: (javadoc java-object-or-class-here)
        Exit: Control+D or (exit) or (quit)
        Results: Stored in vars *1, *2, *3, an exception in *e

        pipetest.core=> (def hello "Hello world!")
        #'pipetest.core/hello
        pipetest.core=> Bye for now!


        Step 3



        You can connect to the REPL, continue after the state changes from the previous step, but now you can use it to interact.



        $ lein repl :connect 0.0.0.0:9000
        Connecting to nREPL at 0.0.0.0:9000
        REPL-y 0.3.7, nREPL 0.2.12
        Clojure 1.8.0
        OpenJDK 64-Bit Server VM 1.8.0_181-8u181-b13-1ubuntu0.18.04.1-b13
        Docs: (doc function-name-here)
        (find-doc "part-of-name-here")
        Source: (source function-name-here)
        Javadoc: (javadoc java-object-or-class-here)
        Exit: Control+D or (exit) or (quit)
        Results: Stored in vars *1, *2, *3, an exception in *e

        pipetest.core=> (str hello "!!!")
        "Hello world!!!!"





        share|improve this answer













        Maybe starting a headless REPL and have two separate steps might work for you?



        Step 1



        Launch a headless REPL, wait for it to start



        $ lein repl :headless :host 0.0.0.0 :port 9000
        nREPL server started on port 9000 on host 0.0.0.0 - nrepl://0.0.0.0:9000


        Step 2



        In another shell, send the commands to the REPL using your command:



        $ cat test.txt 
        (def hello "Hello world!")

        $ cat test.txt | lein repl :connect 0.0.0.0:9000
        Connecting to nREPL at 0.0.0.0:9000
        REPL-y 0.3.7, nREPL 0.2.12
        Clojure 1.8.0
        OpenJDK 64-Bit Server VM 1.8.0_181-8u181-b13-1ubuntu0.18.04.1-b13
        Docs: (doc function-name-here)
        (find-doc "part-of-name-here")
        Source: (source function-name-here)
        Javadoc: (javadoc java-object-or-class-here)
        Exit: Control+D or (exit) or (quit)
        Results: Stored in vars *1, *2, *3, an exception in *e

        pipetest.core=> (def hello "Hello world!")
        #'pipetest.core/hello
        pipetest.core=> Bye for now!


        Step 3



        You can connect to the REPL, continue after the state changes from the previous step, but now you can use it to interact.



        $ lein repl :connect 0.0.0.0:9000
        Connecting to nREPL at 0.0.0.0:9000
        REPL-y 0.3.7, nREPL 0.2.12
        Clojure 1.8.0
        OpenJDK 64-Bit Server VM 1.8.0_181-8u181-b13-1ubuntu0.18.04.1-b13
        Docs: (doc function-name-here)
        (find-doc "part-of-name-here")
        Source: (source function-name-here)
        Javadoc: (javadoc java-object-or-class-here)
        Exit: Control+D or (exit) or (quit)
        Results: Stored in vars *1, *2, *3, an exception in *e

        pipetest.core=> (str hello "!!!")
        "Hello world!!!!"






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 17 '18 at 2:30









        Denis FuenzalidaDenis Fuenzalida

        894714




        894714






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53185866%2fhow-to-drop-into-a-repl-from-within-a-clojure-command-line-application%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Full-time equivalent

            Bicuculline

            さくらももこ