
@sysnajar has joined the channel

Hi there everyone , I’m new to racket. Is there any example of how to execute external process (eg. /usr/bin/ls) and then read inputs from subprocess stdout ?

It’s pretty confusing since I’m from imperative world (Lua) :)

Here’s a quick example:
#lang racket
(with-output-to-string
(λ () (system* "/bin/ls" "-l")))

You can also use (find-executable-path "ls")
so that you don’t need to specify the full path (if it’s on $PATH
)

works really well. Thank you!!

@sysnajar The various flavors are here: https://docs.racket-lang.org/reference/subprocess.html. subprocess
is the most-general — where you get Racket ports for stdin, stdout, stderr — but you might not need all that. I don’t know an example for subprocess
off the top of my head.

Often one of the simpler variations will be all you need, such as system*
which @sorawee pointed out.

@greg yup, i was able to execute the command using subprocess as you suggestes but had no idea how to actually obtain/use its output. Using system* was much simpler (but i’m still courious to know how to archive that usig subprocess) Thank for your reply !!

Here’s an example: [samth@homer:/tmp/xxx racket-7.8] ls
total 0
-rw-rw-r-- 1 samth samth 0 Sep 7 10:42 foo
[samth@homer:/tmp/xxx racket-7.8] r
Welcome to Racket v7.8.
> (define-values (k out in err) (subprocess #f #f #f "/bin/ls" "-l"))
> (subprocess-wait k)
> (port->string out)
"total 0\n-rw-rw-r-- 1 samth samth 0 Sep 7 10:42 foo\n"
>

Are these instructions correct for Windows 10: https://github.com/racket/racket/wiki/Set-your-PATH-environment-variable\|https://github.com/racket/racket/wiki/Set-your-PATH-environment-variable ?

i’ve got a Windows user on the Discord who is having trouble using raco - but I don’t have Windows myself

technically that could work. i usually just do the following: 1. in the task bar “search” box area type: “environment” and the first result is “Edit Environment Variables” 2. that brings up the “System Properties” window. At the bottom click “Environment Variables” 3. the next window lets you edit them. there are 2 sections: “User” and “System”. For a single-user machine, just edit the “User” ones. In the list, find “Path” and double click it to edit…

- Click “Browse” and find the path to “raco.exe” and click “OK”

- Close out all the open environment windows w/ “OK” for each (or it will cancel the changes).
- Finally, the user will need to close any terminal apps open and re-launch them to get the new environment (logout/in is usually the simplest thing to say if dealing w/ someone super non-technical).

Hope that helps @spdegabrielle

Now find myself wishing I’d put all that in a thread :slightly_smiling_face:

Thanks I’ve pasted that to discord to help the user there

How do you feel about updating the wiki page? @massung

I could probably be peer-pressured into doing it. But haven’t done wiki stuff in a looong time

It’s markdown like here so you could just cut and paste the text(and leave the images to another day) :grinning:


I’m on my phone right now so a little tricky for me

Thank you very much .

Done, linking to a great site
