[racket] Call racket with long code from racket

From: Jordan Schatz (jordan at noionlabs.com)
Date: Thu Sep 8 17:16:55 EDT 2011

Niitsuma,

> I am trying to call racket with long code from racket
You might have the wrong idea... calling another racket process to
evaluate some code is probably doing things the hard way. 

Have a look at the eval function:
http://doc.racket-lang.org/reference/eval.html?q=eval#(def._((quote._~23~25kernel)._eval))

Also I'm guessing you might be doing this as a way to manage threads? (as
I've done something similar in PHP to hack around its thread limitations)
Racket has full support for managing threads.
http://doc.racket-lang.org/reference/threads.html?q=thread&q=eval#(def._((quote._~23~25kernel)._thread))

But to answer your question, you can embed " and other special chars in a
string by escaping them with \

#lang racket
(display
 (port->string
  (car
   (process "echo 'Hello World'"))))

(display
 (port->string
  (car
   (process "echo \"Hello World with double quotes\""))))

You dont need the (require racket/system) the `system`, `process` etc
functions are already in #lang racket.

Also make sure that whatever you evaluate with racket -e '(somecode)'
outputs something, or display will have nothing to display.

Shalom,
Jordan

On Fri, Sep 09, 2011 at 05:35:41AM +0900, Niitsuma Hirotaka wrote:
> I am trying to call racket with long code from racket
> -----------
> #lang racket
> (require racket/system)
> (display (port->string (car (process     "racket -e ' [long-code] ' "))))
> -----------
> 
> But long-code contain  "  and  '   .
> Thus
> 
> (process     "racket -e ' [long-long-code] ' "))
> 
> does not work.
> 
> How to  call racket with long code ( contain "  and  '    ) from racket
> 
> Saving long-code into file can not use. Because this is part of web application.
> _________________________________________________
>   For list-related administrative tasks:
>   http://lists.racket-lang.org/listinfo/users


Posted on the users mailing list.