Teach Yourself Scheme: 11.2 Calling operating-system commands

created by washort
(idea) by washort (7 y) (print)   (I like it!) Wed Apr 19 2000 at 0:00:30
Prev Up Next

The system procedure executes its argument string as an operating-system command. It returns true if the command executed successfully with an exit status 0, and false if it failed to execute or exited with a non-zero status. Any output generated by the command goes to standard output.

(system "ls") 
;lists current directory

(define fname "spot")

(system (string-append "test -f " fname)) 
;tests if file `spot' exists

(system (string-append "rm -f " fname)) 
;removes `spot'

The last two forms are equivalent to

(file-exists? fname)

(delete-file fname)

Prev Up Next

Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.