Skip to content

Not possible to inherit process I/O #10

@eraserhd

Description

@eraserhd

Hi!

I need to run a command from within clojure that does two things (one essential, one nice) that require the command to have inherited the process I/O.

  • The first (nice) one is that it prints color when it detects that it is connected to a terminal.
  • The second one is that it will prompt for my SSH passphrase if it needs it when connected to a terminal.

Here's the code that I'd love to replace with conch (but can't right now):

(defn ^:private realtime-output-sh
  "A version of sh in which the child process inherits I/O."
  [& args]
  (let [command-line (take-while string? args)
        {:keys [dir env]} (->> args
                               (drop-while string?)
                               (apply hash-map))
        process-builder (let [pb (doto (ProcessBuilder. command-line)
                                   (.inheritIO)
                                   (.directory (io/file dir)))]
                          (.clear (.environment pb))
                          (doseq [[env-name env-value] env]
                            (.put (.environment pb) env-name env-value))
                          pb)
        process (.start process-builder)
        exit-code (.waitFor process)]
    exit-code))

I'm not sure what the best way to do this would be. Perhaps allowing :inherit as a value for :in, :out, and :err?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions