How to Output Draw.io XML to stdout using graphviz2drawio

Use the --stdout flag when running graphviz2drawio to print the generated Draw.io XML directly to standard output instead of writing to a file.

The hbmartin/graphviz2drawio repository converts GraphViz DOT diagrams into Draw.io-compatible XML format. While the default behavior saves output to a .drawio file, you can output the Draw.io XML to stdout using graphviz2drawio by passing the --stdout flag, enabling seamless integration with shell pipelines, environment variables, and automated workflows.

Using the --stdout Flag

The command-line interface provides the --stdout option to bypass file creation and stream the XML directly to your terminal.

Basic Syntax

To convert a single DOT file and print the XML to the terminal:

graphviz2drawio --stdout mygraph.dot

Piping from stdin

You can combine input redirection with stdout output by using the special filename -, which tells the tool to read GraphViz data from standard input:

cat mygraph.dot | graphviz2drawio --stdout -

Combining with Layout Engines

The -p (or --program) option works independently of output routing, allowing you to specify alternative GraphViz layout engines like neato, fdp, or circo while still printing to stdout:

graphviz2drawio -p neato --stdout mygraph.dot

Capturing Output in Shell Scripts

When automating diagram generation, you can capture the XML directly into a shell variable or pipe it to downstream tools without intermediate files:

#!/usr/bin/env bash

# Convert a DOT file and capture the XML into a variable

xml=$(graphviz2drawio --stdout diagram.dot)

# Send the XML to a web service or process it further

curl -X POST -d "$xml" https://example.com/upload

This pattern eliminates filesystem I/O overhead and keeps sensitive diagrams in memory only.

Technical Implementation Details

The stdout behavior is controlled by three coordinated components in the codebase.

CLI Argument Definition

In graphviz2drawio/models/Arguments.py, the parser defines the --stdout flag that sets the corresponding attribute in the arguments namespace.

Output Decision Logic

In graphviz2drawio/__main__.py, the helper function _determine_single_output inspects the parsed arguments. When --stdout is detected, it returns [None] to signal that no output file path should be generated.

XML Generation and Printing

The _convert_file function in graphviz2drawio/__main__.py calls the core convert() function from graphviz2drawio/graphviz2drawio.py. This function orchestrates the conversion pipeline:

When the outfile parameter is None (as determined by _determine_single_output), the CLI wrapper executes print(output), sending the Draw.io XML directly to stdout.

Summary

  • The --stdout flag directs XML output to the terminal instead of creating a .drawio file
  • Use - as the input filename to read DOT data from stdin while writing to stdout
  • The _determine_single_output helper in __main__.py returns [None] to signal stdout-only mode
  • When outfile is None, the conversion wrapper executes print(output) to emit the XML string

Frequently Asked Questions

Can I pipe a DOT file into graphviz2drawio and get XML on stdout?

Yes. Use the special filename - to read from stdin combined with the --stdout flag: cat diagram.dot | graphviz2drawio --stdout -. This processes the piped input and prints the resulting Draw.io XML to your terminal.

Does the --stdout flag work with alternative layout engines like neato or fdp?

Yes. The -p (or --program) option is independent of output routing. You can specify any GraphViz layout engine while still printing to stdout: graphviz2drawio -p fdp --stdout diagram.dot.

How do I capture the Draw.io XML output into a shell variable?

Use command substitution to store the XML in a variable: xml=$(graphviz2drawio --stdout diagram.dot). The variable now contains the complete XML string, allowing you to manipulate it without creating temporary files.

What happens if I omit the --stdout flag?

Without --stdout, graphviz2drawio writes the XML to a file named after the input file with a .drawio extension (e.g., diagram.dot becomes diagram.drawio) and prints the filepath to stdout instead of the XML content.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →