I can issue bash commands with Racket with (system "some command")
, but the function returns #t instead of the resulting output from the command-line, which it only prints. How can I get the result of the command to be returned with the function?
The system
procedure sets stdout
to the value of the paramter current-output-port
. This means that we can collect everything written to current-output-port
to a string and return that. The construct with-output-to-string
sets current-output-port
to a port that doesn't print anything, but eventually returns whatever written to the port as a string.
> (with-output-to-string (lambda () (system "date")))
"Sat Jun 25 12:20:12 CEST 2016\n"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With