First of all, itβs good for you, wanting to come up with a cleaner solution! You are right that there is a more elegant way to do what you tried.
For starters, using subprocess almost certainly be redundant in your particular use case. racket/system module provides a simpler interface that should be sufficient for your needs. In particular, I would use the system* function, which executes one process with the arguments provided, and then prints its output to stdout.
Using system* , you can create a very general helper function that can execute a command for a specific executable file and returns its output as a string.
(define (execute-command proc-name) (define proc (find-executable-path proc-name)) (Ξ» (args) (with-output-to-string (thunk (apply system* proc args)))))
This function itself returns a new function when it is called. This means that using it to invoke the Git command will look like this:
((execute-command "git") '("checkout" "-q" "master"))
The reason for this will soon become apparent.
Actually, looking at the implementation of execute-command , we use with-output-to-string to redirect all the output from the system* call to a string (instead of just printing it to standard output). This is actually an abbreviation for using parameterize to set the current-output-port parameter, but it is simpler.
With this function, we can easily implement check-status .
(define (check-status) (define commands '(("checkout" "-q" "master") ("rev-parse" "@") ("rev-parse" "@{u}") ("merge-base" "@" "@{u}"))) (map (execute-command "git") commands))
Now the reason for the return (execute-command "git") new function becomes apparent: we can use it to create a function that will then be displayed on the commands list to create a new list of lines.
Also note that the definition of the commands list uses only one ' at the beginning. The definition you provided will not work, and in fact, the ports list that you defined in your initial implementation is not what you expect. This is because '(...) not exactly the same as (list ...) - they are different, so be careful when using them.