Next: , Previous: , Up: posix   [Index]


4.36 Downloading files with curl

The library (vicare posix curl) exports a simple API to download files through the external program curl. This library is a demonstration of the basic mechanism needed to execute an external program and read data from its standard output and standard error.

The source distribution of Vicare includes a simple demo program demo-curl.sps in the tests subdirectory of the source tree.

The executable file curl must be reachable in the current PATH; curl is always with the command line:

curl --silent --show-error

the ASCII text displayed on the standard output and standard error is captured for diagnostic. Additional options can be appended to the command line.

Function: curl url option

Download a file spawning a subprocess that launches curl. url must be a string representing the URL in ASCII encoding. Each option must be a string representing a curl command line argument. When successful: return two strings representing the output of curl to, respectively, standard output and standard error; otherwise raise an exception.

Example:

#!r6rs
(import (vicare)
  (vicare posix curl))

(define (get-it url)
  (receive (out err)
      (curl url)
    (display out)
    (newline)
    (display err)
    (newline)
    (flush-output-port (current-output-port))))

(get-it "http://marcomaggi.github.io/index.html")