1

What's the preferred way to run a raco command from a script?

I've been doing things like:

#lang racket
(system "raco frog -b")

but there has got to be a better solution.

Ben Greenman
  • 1,945
  • 12
  • 22
  • Do you need to run a `raco` command as a part of a Racket script? Or do you just need a way to run a `raco` command? – Gibstick Dec 15 '16 at 17:14
  • Yes, I need to run a `raco` command as part of a Racket script. – Ben Greenman Dec 15 '16 at 17:27
  • Okay, this is going to sound brusque because people are going to think I don't know you, but... can't you pull up the raco source files and see if there's a programmatic interface? – John Clements Dec 15 '16 at 17:40
  • ... so I took a quick one-minute look at the source, and ... I don't see a programmatic interface. I think in this case the response might well be that going straight to the source is the right idea here, and that frog itself should have a programmatic interface. Does it? – John Clements Dec 15 '16 at 17:43
  • `frog` is just an example, I want a programmatic interface to anything that's using `raco` as its interface – Ben Greenman Dec 15 '16 at 18:34

1 Answers1

2

Yes indeed, there is a better way:

#lang racket
(require raco/all-tools)
(define v (all-tools))
(parameterize ([current-command-line-arguments (vector "-b")])
  (dynamic-require (second (hash-ref v "frog")) #f))

Many thanks to Sam Tobin-Hochstadt.

https://github.com/racket/racket-lang-org/pull/26#issuecomment-267160884

Ben Greenman
  • 1,945
  • 12
  • 22