Search code examples
windowscommand-linegraphviz

Pipe dot graphviz with echo windows from command line gives corrupted output


I'm trying to make an svg from an inline stdin (like in the documentation) :

C:\Users\VERBOSE\Desktop>echo 'digraph { a -> b }' | dot -Tsvg > output.svg

Surprisingly, this gives two files :

enter image description here

The output.svg in the browser shows : This XML file does not appear to have any style information associated with it. The document tree is shown below.

And why I open the b file in notepad, I see this : 'digraph { a - }'

I'm not a windows expert but I think it has to do with the > that is not being escaped.

An important detail, when I create a dot file manually and run the command below, it works :

C:\Users\VERBOSE\Desktop>dot file.dot -Tsvg -o output2.svg

enter image description here

Can you guys propose a solution ? I tried escaping the > and removing the quotes, the command runs without errors but no svg file is created :

C:\Users\VERBOSE\Desktop>echo digraph { a -^> b } | dot -Tsvg -o "output3.svg"

UPDATE : The first command in my post works fine with PowerShell :

PS C:\Users\VERBOSE\Desktop> echo 'digraph { a -> b }' | dot -Tsvg > output.svg

enter image description here


Solution

  • I think it is all about the possibilities of the shells used. The example in the documentation is geared towards *nux (seen the $ as prompt). The "normal" Windows command line is very limited, to escape a character one needs a ^ (see also https://en.wikipedia.org/wiki/Escape_character#Windows_Command_Prompt for escape characters). This will not work properly yet as the pipe symbol will sill get the > character so we have to see to it that what ends up after the pipe symbol is correctly interpreted again, so we need to have 3 times the ^ as we need to escape also to escape the ^ going through the pipe.

    So the result for this simple example will be:

    echo digraph { a -^^^> b } | dot -T svg > output.svg