--- title: "Output, JSON and exit codes" description: "What darkgrade commands print for scripts: JSON results, where files are saved, exit codes, error messages, held commands and environment variables." url: https://darkgrade.com/docs/cli/output last_updated: 2026-12-04 docs_index: https://darkgrade.com/docs/llms.txt --- # Output, JSON and exit codes > What darkgrade commands print for scripts: JSON results, where files are saved, exit codes, error messages, held commands and environment variables. > ## Documentation Index > Fetch the complete documentation index at: https://darkgrade.com/docs/llms.txt > Use this file to discover all available pages before exploring further. Write scripts that can rely on what `darkgrade`, the Darkgrade CLI, prints. Results go to standard output, everything else goes to standard error, and the exit status says whether the command worked. ## The contract | Channel | Carries | | - | - | | **Standard output** | The result, and nothing else | | **Standard error** | Progress, questions, warnings and errors | | **Exit status 0** | The command succeeded | | **Exit status 1** | The command failed, a check did not pass, or the arguments were not understood | Colour, the spinner and questions appear only on a terminal. In a pipe, a script or cron you get plain, stable output and are never asked anything. Two commands exit 0 when you might expect 1: `cameras` with no camera attached, and `camera recover` when the camera did not come back. Test their JSON instead ([`cameras`](#doctor-and-cameras), [`recover`](https://darkgrade.com/docs/cli/scripting.md#handle-failures)). ```bash if photo=$(npx darkgrade camera take-photo --json); then echo "Saved $(jq -r '.name' <<<"$photo") to the card" else echo "The camera did not take the photo" >&2 fi ``` ## JSON results Pass `--json` after the command to get the result as one JSON document on one line. Camera commands print the same value that [Slate](https://darkgrade.com/docs/slate/getting_started/quickstart.md) returns for that operation; each section in [Functionality](https://darkgrade.com/docs/functionality/connection.md) lists its fields under **What you get back**. | Command | Prints | | - | - | | `get-`, `set-` | The value as a JSON string: `"ISO 800"` (a number for colour temperature and audio level) | | `get-battery`, `get-info`, `get-capabilities` | An object | | `get-card-status`, `list-media` | An array, one entry for each card slot or file | | `autofocus`, `get-recording-state` | A JSON string such as `"acquired"` or `"idle"` | | `zoom-to` | A number: the focal length where the lens landed | | Commands with nothing to return (`set-focus-point`, `set-clock`, `connect`) | `null` | A string result keeps its JSON quotes. Use `jq -r` to strip them: ```bash iso=$(npx darkgrade camera get-iso --json | jq -r .) # ISO 800 ``` ### Examples: battery, card and files A camera leaves out any field it does not report, so read optional fields with a fallback: `jq '.percent // empty'`. ```bash npx darkgrade camera get-battery --json ``` ```json {"percent":82,"powerSource":"battery"} ``` ```bash npx darkgrade camera get-card-status --json ``` ```json [{"slot":1,"state":"ready","writable":true, "freeBytes":59055800320,"photosRemaining":1532}] ``` ```bash npx darkgrade camera list-media --json ``` ```json [{"id":"…","name":"DSC01234.JPG","kind":"photo","slot":1, "sizeBytes":8437760,"capturedAt":"2026-11-24T14:05:09", "previews":["thumbnail","preview"]}] ``` ### Without --json Camera commands print JSON either way: indented on a terminal, on one line when piped. These commands print text for people unless you pass `--json`: | Command | Without `--json` | | - | - | | `cameras` | A table on a terminal; tab-separated `name`, `id`, `state` when piped | | `doctor` | A checklist | | `camera start-recording` | `Stopped. C0001.MP4 (12.3 MB) is on the card.` | | `camera watch` | The event's name, one per line | | `telemetry benchmark` | A short summary | | `telemetry status` | A table on a terminal; JSON when piped | Passing `--json` everywhere in scripts keeps this simple. ## Files Four commands return a file: `take-photo` (with `--destination computer` or `computerOnly`), `get-live-view-frame`, `get-media-preview` and `download-media`. `--output ` says where to write it. ```bash npx darkgrade camera take-photo --destination computer \ --output photo.jpg --json ``` ```json {"result":{"destination":"computer","mediaId":"…","name":"DSC01234.JPG", "sizeBytes":8437760,"data":{"file":"DSC01234.JPG","bytes":8437760}}, "files":[{"role":"photo","path":"photo.jpg","bytes":8437760}]} ``` When a command writes a file, its output is `{ result, files }`: `result` is the operation's own result with the bytes replaced by `{ file, bytes }`, and `files` lists what was written and where. Read the path with `jq -r '.files[0].path'`. Without `--output`, the file is saved in the current folder: | Command | Default file name | | - | - | | `take-photo` | The camera's own name for the photo, such as `DSC01234.JPG` | | `get-live-view-frame` | `get-live-view-frame-frame.jpg` | | `get-live-view-frame --overlay` | Also `get-live-view-frame-overlay.png`; with `--output frame.jpg`, `frame-overlay.png` | | `get-media-preview ` | `-preview.jpg` | | `download-media ` | `-download.jpg` for a JPEG; `-download`, with no extension, for anything else | > [!TIP] > > Give `download-media` an `--output` with the file's real name, which [`list-media`](https://darkgrade.com/docs/functionality/media.md#list-photos-and-clips) reports as `name`. The [card backup recipe](https://darkgrade.com/docs/cli/scripting.md#back-up-the-card) does this for every file. `--output` writes exactly the path you give. It does not convert formats: a RAW photo saved as `photo.jpg` is still a RAW file. ## Errors A failure prints an `error:` line on standard error and exits 1. A command that failed before it had a result prints nothing on standard output, so a pipe into `jq` gets nothing rather than half a result. ```text $ darkgrade camera take-photo --destination nowhere error: takePhoto: destination must be one of card, computer, computerOnly Usage: darkgrade camera take-photo [options] Run "darkgrade camera take-photo --help" for details. ``` | What went wrong | What you see | | - | - | | The arguments were not understood | The reason, the command's usage line and a pointer to its help. Inputs are checked before the camera is opened | | No camera is ready | `No camera found.` and the USB mode to set for each brand | | The `--camera` you named is not attached | `error: No USB devices available` | | Several cameras are attached | The list, with the exact `--camera` line for each | | The camera refused, or does not support the operation now | `error:` and the reason in plain words | | The camera did not confirm the result | `error:` and what could not be confirmed | Set `DARKGRADE_DEBUG=1` to print the stack trace of a failure. > [!WARNING] > > Every command is sent to the camera once. When a result cannot be confirmed, the CLI reports it and exits 1; it never sends the command again. Before your script retries a command that changes something (`take-photo`, `set-*`, `start-recording`), read the camera's state first, or you may take two photos. Commands that only read (`get-*`, `list-media`, `download-media`) are safe to retry. ## Commands that hold Three commands stay in the foreground until you stop them. Stop one with Ctrl+C, by sending it `SIGTERM`, or by giving it `--duration`. | Command | Holds while, then | | - | - | | [`camera start-recording`](https://darkgrade.com/docs/functionality/video.md#start-recording) | The camera records. Then it stops recording, waits for the finished clip on the card and prints it. | | [`camera start-zoom`](https://darkgrade.com/docs/functionality/zoom.md#start-zooming) | The lens zooms, for 10 seconds at most. Then it stops the zoom. | | `camera watch` | It prints a line for each camera event. Then it closes the camera. | `--duration` takes a number with a unit (`ms`, `s`, `m` or `h`), from `1s` to `24h`: `10s`, `1.5s`, `2m` and `1h` are fine, `500ms` is too short. A bare number is seconds. ```bash npx darkgrade camera start-recording --duration 30s --json ``` ```json {"stopped":true, "clip":{"mediaId":"…","name":"C0001.MP4","sizeBytes":187432960}} ``` If the camera does not confirm that recording stopped, the command prints `"stopped": false` with the camera's `state` and an `error`, exits 1, and leaves the camera's session open rather than closing it under a take that may still be running. Check the camera before unplugging it. `start-recording` prints its progress (`Recording for 30s. Ctrl-C stops sooner.`) on standard error even with `--quiet`. ### Watch for events `watch` opens the camera read-only and prints a line each time something changes on it, until you stop it: ```bash npx darkgrade camera watch --json ``` ```json {"event":"settingsChanged","at":"2026-12-03T18:04:11.212Z"} {"event":"mediaAdded","at":"2026-12-03T18:04:15.874Z"} ``` | Event | Means | | - | - | | `settingsChanged` | A setting changed on the camera, for example someone turned a dial | | `mediaAdded` | A new photo or clip is on the card | An event says that something changed, not what. Follow it with `get-capabilities` or `list-media` once `watch` has exited. ## doctor and cameras ```bash npx darkgrade cameras --json ``` ```json {"cameras":[{"usbId":"054c:0f51","vendor":"Sony Group Corporation", "vendorId":1356,"productId":3921,"serialNumber":"…", "model":"ILCE-7M5","state":"ready"}]} ``` `state` is `ready`, or `other-mode` for a camera attached in card-reader or another USB mode. `cameras` exits 0 even when it finds none: test for a ready camera with `jq -e`: ```bash npx darkgrade cameras --json | jq -e 'any(.cameras[]; .state == "ready")' > /dev/null ``` ```bash npx darkgrade doctor --json ``` ```json {"version":"0.1.0-alpha.1","healthy":true,"checks":[ {"name":"node","outcome":"passed","detail":"Node 24.3.0 on darwin arm64"}, {"name":"camera","outcome":"warning","detail":"No camera found", "remedy":"…"}]} ``` Each check has a `name` (`node`, `settings`, `usb-driver`, `camera`), an `outcome` (`passed`, `warning` or `failed`), a `detail`, and a `remedy` when it did not pass. `healthy` is false, and the exit status 1, only when a check failed. ## Environment variables | Variable | Effect | | - | - | | `DARKGRADE_CAMERA` | The camera to use, as `VID:PID`, when several are attached. `--camera` wins | | `NO_COLOR` | Any value turns colour off | | `FORCE_COLOR` | Any value except `0` or `false` keeps colour when output is piped. `--no-color` wins over both | | `CI` | Any value turns the spinner and every question off. `TERM=dumb` does the same, and turns colour off | | `DARKGRADE_NO_SPINNER` | Any value replaces the spinner with one plain line for each step | | `DARKGRADE_DEBUG` | Any value prints the stack trace of a failure | | `DARKGRADE_HOME` | The settings folder. The default is `~/.darkgrade`, shared with Studio | | `DARKGRADE_CONTRIBUTIONS`, `DO_NOT_TRACK` | `DARKGRADE_CONTRIBUTIONS=0` or `DO_NOT_TRACK=1` stops [sharing](https://darkgrade.com/docs/cli/telemetry.md), whatever the saved preference | | `DARKGRADE_TELEMETRY_URL` | The collector's address, for a private deployment | The [global flags](https://darkgrade.com/docs/cli.md#global-flags) `--quiet`, `--no-color`, `--no-input` and `--no-progress` do the same from the command line. ## Next > [card] [Scripts and automations](https://darkgrade.com/docs/cli/scripting.md) > > Recipes that use all of this. > [card] [Command reference](https://darkgrade.com/docs/cli/commands.md) > > Every command with its inputs and flags.