# QR code command line tool

**URL:** <https://racket.discourse.group/t/qr-code-command-line-tool/4276>\
**Category:** Show & Tell\
**Tags:** racket-at-work\
**Created:** [June 4, 2026, 11:12am UTC](https://racket.discourse.group/t/qr-code-command-line-tool/4276 "2026-06-04T11:12:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![spdegabrielle](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/spdegabrielle/32/95_2.png) [@spdegabrielle](https://racket.discourse.group/u/spdegabrielle)\
**Post date:** [June 4, 2026, 11:12am UTC](https://racket.discourse.group/t/qr-code-command-line-tool/4276/1 "2026-06-04T11:12:42Z")

</div>

A colleague needed to make QR codes so I made a command line tool.

I installed [simple-qr](https://pkgs.racket-lang.org/package/simple-qr) with `raco package install`,  
then I searched for and installed the `drracket-cmdline-args` DrRacket plugin using graphical package manager in DrRacket so I could test it.  
Once complete I used 'Create Executable' in DrRacket to create a version my colleague could use on their machine

```scheme
#lang racket/base
(require simple-qr)
(define (main)
  (define (my-error text)
    (fprintf (current-error-port) "Error: ~a\n" text))
  (define args (current-command-line-arguments))
  (when (not (= (vector-length args) 2))
    (my-error "Usage: qr <url> <filename>")
    (exit 1))
  (define url-str (vector-ref args 0))
  (define filename (vector-ref args 1))
  (with-handlers ([exn:fail?
                   (lambda (e)
                     (fprintf (current-error-port)
                              "Error: ~a\n"
                              (exn-message e))
                     (exit 1))])
    (qr-write url-str filename)) ;(qr-write "https://www.something.com/" "myqr.png")
  (displayln (string-append "QR code for " url-str " to " filename " as PNG")))
(main)

```

Could not have done this without the Racket community 😍

---

<div class="post-metadata">

**Author:** ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)\
**Post date:** [June 4, 2026, 3:36pm UTC](https://racket.discourse.group/t/qr-code-command-line-tool/4276/2 "2026-06-04T15:36:12Z")

</div>

Nice. (I have used the QR package a lot, so yes, thanks to the creator.)

May I suggest a second look:

```scheme
#! /bin/sh
#|
exec racket -qu "$0" ${1+"$@"}
|#
#lang racket/base

;; ./qr URL FileName creates a QR for `URL` and deposits it in `FileName`

(provide main)

(require simple-qr)

;; ---------------------------------------------------------------------------------------------------
#; {String String -> Void}
(define main
  (case-lambda
    [(url-str filename) (make-qr url-str filename)]
    [_ (use-as)]))

#; {String String -> Void}
(define (make-qr url-str filename)
  (with-handlers ([exn:fail? (lambda (e) (eprintf "Error: ~a\n" (exn-message e)) (exit 1))])
    (qr-write url-str filename))
  (displayln (string-append "QR code for " url-str " to " filename " as PNG")))

(define (use-as)
  (eprintf "expected usage: ./qr URL FileName\n")
  (exit 1))

```
