add a write-to-file function for exporting stuff

This commit is contained in:
Leo Butler 2020-12-08 12:46:16 -06:00
parent 35d0099e40
commit fba4b359fa
1 changed files with 8 additions and 0 deletions

View File

@ -27,6 +27,14 @@
(define (roundx x) (inexact->exact (round x)))
(define (write-to-file obj filename)
(let ((port (open-file filename "w")))
(catch 'write-error
;; thunk
(lambda () (simple-format port "~a" obj) (force-output) (close port))
;; handler
(lambda () (close port) 'write-error))))
(define* (shell-command-to-string* cmd args)
(let* ((port (apply open-pipe* (append (list OPEN_READ cmd) args)))
(str (read-string port)))