popen-read

Synopsis

(popen-read command)

Parameters

  • command

Description

This procedure creates an input port by invoking popen() with the specified command (a string). The created input port is closed by garbage collection is no longer referenced (by calling pclose()) or may be closed explicitely (using close-input-port or close). Reading from a closed input port results in an error.

Side Effects

Return Value

The created input port is returned.

Example

> (popen-read "echo 1234")
#<input-port>
> (read (popen-read "echo 12345"))
12345
> (read (popen-read "notfound"))
sh: notfound: command not found
#<end-of-file>
> (define port (popen-read "echo 12345"))
port
> (close-input-port port)
ok
> (read port)

ERROR!
 message   : cannot read from port
 irritant  : #<primitive-procedure internal-read>
 expression: infunction
 continue  : possible, continue with value as value from primitive

Error (? for help) >>