[racket] Call racket with long code from racket

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Wed Sep 14 14:46:24 EDT 2011

On Tue, Sep 13, 2011 at 8:03 AM, Noel Welsh <noelwelsh at gmail.com> wrote:
> That is not one expression, but several. Wrap it in a (begin ...) and
> it should work. I.e.

Yikes!  Don't continue to encourage him to use process here.

At the very least, even the raw use of eval is probably safer than
what's being proposed.

Trying to get the shell escapes right is a losing proposition.
Rodolfo called it not the most "safe or beautiful".  I'd say that
warning more strongly: it's absolutely unsafe to do it this way.  For

#lang racket
(define (do-it thing)
  (process (format "racket -e \"~a\""
(port->string (fourth (do-it "$HOME")))

When I run this on my home machine, I see:

    "reference to undefined identifier: /home/dyoo\n"

which shows that the quoting and unquoting from my shell is coming
into effect here, before Racket gets a handle.

Which means stuff like:

    (port->string (fourth (do-it "`yes`")))

will cause infinite loops, because my shell allows for backquote
evaluation.  You can imagine all sorts of other silliness there, and
not of the benign kind.

Posted on the users mailing list.