pallet / stevedore

A shell script embedding in clojure
93 stars 14 forks source link

Create commands for IO Redirection #4

Closed frenchy64 closed 5 years ago

frenchy64 commented 13 years ago

Bash has plenty of IO redirection commands like < and <&-.

These could possibly be mapped to commands as such:

(redir :stdout
  (~java :classpath [@CLOJURE_JARS @VIMCLOJURE_JAR]
     :server true
     :main-class vimclojure.nailgun.NGServer
     :args @port))

A comparison to Windows IO redirection commands should also be made to try and create a set of stevedore scripts for both OS's.

frenchy64 commented 13 years ago

Here is a proposed solution.


(with-script-context [:default]
  (script
    (~with-redir [[:err :out]
                  [:out "file.txt" :append true]
                  [:err "err.txt"]
                  [[:out :err] "/dev/null"]]
      (echo "asfd")
      (echo "asfd")
      (echo "asfd"))))

=>

{
 echo "asdf"
 echo "asdf"
 echo "asdf"
} 1>&2 >>file.txt 2>err.txt &>/dev/null
icylisper commented 13 years ago

How do pipes work ? echo "asdf" | something . with-redir can take a :pipe keyword

frenchy64 commented 13 years ago

Pipes are already in stevedore.

(with-script-context [:default]
  (script
    (pipe (echo "asfd")
          (grep "a")
          (echo))))

=>

echo asfd | grep a | echo

Does it make sense to keep the distinction between pipes and IO redirection?

icylisper commented 13 years ago

Makes sense. with-redir is quite an useful macro to have

hugoduncan commented 13 years ago

I would name it with-redirect