sysnajar
2020-9-7 10:14:39

@sysnajar has joined the channel


sysnajar
2020-9-7 10:16:31

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 ?


sysnajar
2020-9-7 10:17:14

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


sorawee
2020-9-7 10:31:44

Here’s a quick example:

#lang racket (with-output-to-string (λ () (system* "/bin/ls" "-l")))


sorawee
2020-9-7 10:32:29

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


sysnajar
2020-9-7 10:49:31

works really well. Thank you!!


greg
2020-9-7 11:57:11

@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.


greg
2020-9-7 11:58:20

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


sysnajar
2020-9-7 12:01:43

@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 !!


samth
2020-9-7 14:43:23

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" >



spdegabrielle
2020-9-7 15:30:35

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


massung
2020-9-7 16:34:49

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…


massung
2020-9-7 16:36:05
  1. Click “Browse” and find the path to “raco.exe” and click “OK”

massung
2020-9-7 16:37:24
  1. Close out all the open environment windows w/ “OK” for each (or it will cancel the changes).
  2. 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).

massung
2020-9-7 16:37:34

Hope that helps @spdegabrielle


massung
2020-9-7 16:39:09

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


spdegabrielle
2020-9-7 16:39:28

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


spdegabrielle
2020-9-7 16:39:49

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


massung
2020-9-7 16:40:47

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


spdegabrielle
2020-9-7 16:41:53

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



spdegabrielle
2020-9-7 16:42:42

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


sysnajar
2020-9-7 17:56:28

Thank you very much .


massung
2020-9-7 18:06:52

Done, linking to a great site