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

4.37 Downloading files with wget

The library (vicare posix wget) exports a simple API to download files through the external program wget. 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-wget.sps in the tests subdirectory of the source tree.

The executable file wget must be reachable in the current PATH; the library does not use default options for the command line of wget; the ASCII text displayed on the standard output and standard error is captured for diagnostic.

Function: wget option

Perform an operation spawning a subprocess that launches wget. Each option must be a string representing a wget command line argument. When successful: return two strings representing the output of wget to, respectively, standard output and standard error; otherwise raise an exception.


(import (vicare)
  (vicare posix wget))

(define (get-it url)
  (receive (out err)
      (wget "--output-document=-" url)
    (display out)
    (display err)
    (flush-output-port (current-output-port))))

(get-it "")