Thanks for the hint Matt, I noodled around a bit and the code below is what I've come up with, posted here in case it's of use to others.<br><br>Basically, to find the data file:<br>If the (find-system-path 'run-file) or (find-system-path 'exec-file) refer to a (Windows) racket binary (racket.exe, gracket.exe, DrRacket.exe, or the CGC variants) then the source code is being executed, so use the directory containing the source module,<br>
otherwise a generated (i.e. with raco exe) binary is being executed, so use the directory containing the (find-system-path 'run-file).<br><br>I've tested running the source and binary in every fashion I could think (from DrRacket, from command line with racket.exe and pals, from windows icon, from windows shortcut icon, from various different directories) and the data file is located reliable.<br>
<br>Unfortunately, I could not come up with a way to use define-runtime-path, and so I have lost the ability for 'raco distrib' to bundle up the data file automatically, and so will have to add a copy of the data file to the directory after 'raco distrib' completes. (It seems ...\collects\compiler\distribute.rkt copies and changes the names (paths) of the runtime files into the distribution directory as part of assemble-distribution procedure and changing the destination location doesn't look trivial). <br>
<br>Cheers,<br><br>Kieron.<br><br>****<br><br>#lang racket<br><br>(require racket/runtime-path)<br>(require syntax/location)<br><br>; Access a file "data.txt" at run-time that is <br>; located in the same directory as the module source file<br>
; if executing with racket binaries then use the source module location<br>; otherwise use the location of the compiled exe<br>(define (get-data-file-name)<br> ; check for Windows binaries - change for other OS's<br>
(define DrRacket? (regexp-match? #rx".*(?i:DrRacket)(?i:cgc)?\\.(?i:exe)" (find-system-path 'run-file)))<br> (define racket? (regexp-match? #rx".*(?i:racket)(?i:cgc)?\\.(?i:exe)" (find-system-path 'exec-file)))<br>
(let-values <br> ([(p f b) <br> (split-path <br> (path->complete-path <br> (if (or racket? DrRacket?) <br> (quote-module-name) <br> (find-system-path 'run-file))))])<br>
; (printf "get-data-file-name: returning:\"~a\"~n" (build-path p "data.txt"))<br> (build-path p "data.txt")<br> ))<br><br>(define (read-data)<br> (let ([data-file (get-data-file-name)])<br>
(printf "read-data: data-file:\"~a\"~n" data-file)<br> (with-input-from-file data-file<br> (lambda ()<br> (read-bytes (file-size data-file))<br> ))))<br><br>(read-data)<br><br>
<br><div class="gmail_quote">On Tue, Jul 17, 2012 at 6:39 AM, Matt Jadud <span dir="ltr"><<a href="mailto:jadudm@gmail.com" target="_blank">jadudm@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Kieron,<br>
<div class="im"><br>
On Mon, Jul 16, 2012 at 5:13 PM, Kieron Hardy <<a href="mailto:kieron.hardy@gmail.com">kieron.hardy@gmail.com</a>> wrote:<br>
> How do I get a run-time path in the executable created by 'raco distrib',<br>
> that is the same, relative to the directory containing the source racket<br>
> code and the executable created by 'raco exe'?<br>
<br>
</div>I used something along the lines of<br>
<br>
(define (UMBRELLA)<br>
(simplify-path<br>
(build-path<br>
(find-system-path 'run-file) 'up 'up)))<br>
<br>
which allowed me to run my application both as a double-clickable Mac<br>
app as well as from the command line with<br>
<br>
racket foo.rkt<br>
<br>
I think some relevant (recent) discussion on this was here:<br>
<br>
<a href="https://groups.google.com/d/topic/racket-users/CqTiuhY6Aks/discussion" target="_blank">https://groups.google.com/d/topic/racket-users/CqTiuhY6Aks/discussion</a><br>
<br>
By "I think" I mean "I asked this roughly a week ago, and I think it<br>
answers your question.<br>
<br>
Cheers,<br>
Matt<br>
</blockquote></div><br>