Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uiop:run-program with string input #19

Open
epipping opened this issue Nov 6, 2016 · 0 comments
Open

uiop:run-program with string input #19

epipping opened this issue Nov 6, 2016 · 0 comments

Comments

@epipping
Copy link

epipping commented Nov 6, 2016

Hi,

I was looking at how different projects on quicklisp use uiop:run-program and came across this snippet in common-doc:

(defmethod expand-macro ((plot gnuplot))
  "Take the gnuplot source code from the children and the image name, render it
with gnuplot into an image."
  (let* ((pathname (absolute-path (image-path plot)))
         ;; The gnuplot commands
         (text (text (first (children plot))))
         ;; The gnuplot commands to set output format, file etc.
         (input (format nil "set term pngcairo; set output ~S; ~A~%"
                        (namestring pathname)
                        text))
         ;; The gnuplot command
         (command "gnuplot"))
    ;; Run
    (handler-case
        (progn
          (with-input-from-string (stream input)
            (uiop:run-program command :input stream))
          (make-image (namestring (relativize-pathname pathname))))
      (t ()
        (make-text "gnuplot error.")))))

I wanted to let you know that passing input to uiop:run-program through a stream, especially one that isn't a file stream, is not very portable. But you can also pass strings directly (that's far more portable because it internally uses a file). So e.g.

(uiop:run-program "cat" :input '("hello, world") :output :interactive)

will print "hello, world".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant