Yes
@soegaard2 your tool might be helful then
i am using racket to develop a set of tools for differential privacy
That’s a great write up !
I voted in both places [http://lobste.rs\|lobste.rs & HN] and saw my vote count.
done
Ist there a way to pass a racket string to subprocess
stdin?
when I use open-input-string
it complains that it’s not a file-stream-port?
The subprocess’s stdin will be an output port from Racket.
well open-output-string
doesn’t work either for the same reason
I think you need to use the output port returned from subprocess and write to it
Wait - how are you using open-input-string
and open-output-string
? They are used to read and write directly from strings - so as such they are unrelated to subprocess
.
(it’s been a while since I’ve shell scripted in racket)
The code I am trying to run is: (subprocess #f (open-output-string "hello") #f "cat")
or open-input-string
, I am not quite sure
Yeah IIRC you pass #f
and it will give you an output port that will be connected to the process stdin
pass #f
where?
Hmm. I’ll try that.
@cperivol where you passed the open-output-string
call
I thought, this would work: #lang racket
(define in (open-input-string "hello"))
(define out (open-output-string "my standard out port"))
(define err (open-output-string "my error port"))
(subprocess out in err "cat")
(get-output-string out)
But it turns out that out
needs to be a file stream port.
@samdphillips is right actually
(define-values
(pr stdout stdin stderr)
(subprocess #f #f #f "/bin/cat"))
(displayln "hello world" stdin)
(flush-output stdin)
(read-line stdout)
I imagine they need to be file stream ports because then it can skip all of the port machinery and just hand the file descriptor to the subprocess.
cool, do you know how I can send end of file?
Just close the output port
@cperivol In a program of mine, I use ;; Markdown-String -> HTML-String
;;
;; Convert Markdown string to HTML string.
(define (markdown->html markdown-string)
(define output-port (open-output-string))
(parameterize ([current-input-port (open-input-string markdown-string)]
[current-output-port output-port])
(define exit-code
(system*/exit-code
; If the executable isn't found (result is `#f`), provide a binary name
; so that `system*/exit-code` doesn't fail with a contract violation
; but with the user error below.
(or (find-executable-path "pandoc") "pandoc")
"--standalone"
"--css=../css/mvp_custom.css"
"--from=markdown"
"--to=html5"
; Write HTML to stdout.
"--output=-"
; Read Markdown from stdin.
"-"))
(when (not (= exit-code 0))
(raise-user-error "pandoc execution failed with exit code" exit-code)))
(get-output-string output-port))
I’m not using subprocess
here, but system*/exit-code
. Maybe you can use system*/exit-code
similar to here or apply the pattern to subprocess
.
My rule of thumb is if you are just going to wait on the output (synchronous style) use system*
(and friends). If you are going to interact with a process (asynchronous style) use subprocess
If you need to do something complicated wrap subprocess
with abstractions
Does raco make file.rkt
try to open the requires mentioned in file.rkt
? It seems inconsistent…
Yes
I’m not sure what you mean by “inconsistent”. What is inconsistent?
so im trying to get my executable size small and fully self contained: raco demod cliapp.rkt
raco exe --embed-dlls .\cliapp_rkt_merged.zo
and although it reduced the size from 57MB to 25MB if fi didnt use demod
, it wont work standalone.. ffi-lib: could not load foreign library
path: libintl-9.dll
system error: The specified module could not be found.; win_err=126
context...:
body of '#%mzc:cliapp_rkt_merged
these are all of the dependencies its using: libcairo-2.dll* libgmodule-2.0-0.dll* libpangocairo-1.0-0.dll*
libeay32.dll* libgobject-2.0-0.dll* libpangoft2-1.0-0.dll*
libexpat-1.dll* libgthread-2.0-0.dll* libpangowin32-1.0-0.dll*
libffi-6.dll* libharfbuzz-0.dll* libpixman-1-0.dll*
libfontconfig-1.dll* libiconv-2.dll* libpng16-16.dll*
libfreetype-6.dll* libintl-9.dll* ssleay32.dll*
libfribidi-0.dll* libjpeg-9.dll* zlib1.dll*
libglib-2.0-0.dll* libpango-1.0-0.dll*
``it uses 2htdp/image among a few things but I have no idea wlhy its including
libeay32.dll(a library that contains encryption functions which allow for coded communications over networks. ) because this cli program doesnt do any networking... it just slices and manipulates images.
edit: ahh, i think its cause 2htdp/image
(bitmap/url url)` …
Anyone know how i can get my executable size smaller? I’m already using racket/base and only trying to pull in what i need
I think the inconsistency has to do with Racket 7.9 [bc] vs 8.1 [cs]
Basically, the 8.1 [cs] wouldn’t care if the dependent requires were compiled first but the 7.9 [bc] errored out with a standard-module-name-resolver: collection not found
if the dependent require hadn’t been compiled yet.
Interesting. collection not found
is usually not an error about whether it’s compiled though. It’s an error whether the package is installed
Perhaps in 8.1 you installed the package, but in 7.9 you did not?
that’s possible, yeah
how do I check?
Try raco pkg show <package-name>
Or actually, when you run it, shouldn’t you also get the collection not found
error?
huh, no, it’s not installed on 8.1
What is the collection?
That it complains “collection not found”
i think there may be another issue
i think it’s instead require-ing in outdated .zo files that themselves have bad requires
I’m trying something that’s probably not going to work very well… building .zo files via an external make process.
I think that process will need the full dependencies
OK, that sounds complicated, and I don’t fully understand the situation that you are in. But good luck!
A similar question was asked on the beginners channel a while ago: https://racket.slack.com/archives/C09L257PY/p1630479646033100
yeah, i guess there isnt any other way then unless i remove the dependency on 2htdp image… I guess its not too bad because imagemagick is 34MB