As other people already said, this way of doing things is not the most "safe and beautiful" way of getting what you need done.<div>If "long-code" is really long and important, I suggest investigating other solutions.</div>
<div><br><div><br></div><div>As Eli pointed out there are many weird conventions to pay attention depending on your shell.</div><div>When you pass the string with quotes as in your example, I get an error like this: /bin/sh: Syntax error: EOF in backquote substitution</div>
<div>Because bash is waiting for a second `.</div><div><br></div><div>Using a string would also make it difficult to write strings, because you'd need to escape the double-quotes "\"this is a string\"" (and they will most likely conflict with your shell).</div>
<div><br></div><div>The code below will show how the external code will be called and the stdout/stderr (so you can see what's going wrong).</div><div><br></div><div>Using a quoted form instead of a string hides the problem of having ` and ' and instead use quasiquote and quote.</div>
<div><br></div><div>[]'s</div><div><br></div><div>Rodolfo Carvalho</div><div><br></div><div><br></div><div><br></div><div><div>#lang racket</div><div>(define external-code (format "/opt/racket/bin/racket -e \" ~a \""</div>
<div> '(begin</div><div> (require mzlib/defmacro)</div><div> (define-macro (my-when</div><div> test . body)</div>
<div> `(if ,test (begin ,@body) '()))</div><div> (my-when #t '(5 6 7)))))</div><div><br></div><div><br></div><div>(displayln external-code)</div>
<div>(newline)</div><div><br></div><div>(display</div><div> (string-join</div><div> (let* ([p (process external-code)]</div><div> [stdout (first p)]</div><div> [stderr (fourth p)])</div><div> (map port->string (list stdout stderr)))</div>
<div> ""))</div></div><div><br></div><div><br><br><div class="gmail_quote">On Tue, Sep 13, 2011 at 08:22, Niitsuma Hirotaka <span dir="ltr"><<a href="mailto:hirotaka.niitsuma@gmail.com">hirotaka.niitsuma@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">> You could try something like this:<br>
> #lang racket<br>
> (require racket/system)<br>
> (display (port->string (car (process (format "racket -e '~a' " '(+ 2 3))))))<br>
<br>
</div>That does not work in the following case<br>
<br>
(display (port->string (car (process (format "racket -e \" ~a \" "<br>
"<br>
(require mzlib/defmacro)<br>
(define-macro (my-when<br>
test . body)`(if ,test (begin ,@body) '() ))<br>
(my-when #t '(5 6 7))<br>
"<br>
)))))<br>
<div><div></div><div class="h5">_________________________________________________<br>
For list-related administrative tasks:<br>
<a href="http://lists.racket-lang.org/listinfo/users" target="_blank">http://lists.racket-lang.org/listinfo/users</a><br>
</div></div></blockquote></div><br></div></div>