kol
kol

Reputation: 13

Ruby GraphViz DOT Incorrectly Rendering PNGs

I'm making a small program to render some images of binary trees for a class. I want the program to automatically make a bunch of .dot and .png files for me, but the line to render the .png's isn't working unless I manually call it. The trouble code:

@file_num = 0

data.each do |x|
    @tree.add(x)
    draw_frame(@tree, @filename, @file_num)
    @file_num += 1
end


(0...(data.length)).each do |x|
    `dot -Tpng #{@filename}#{x}.dot > #{x}.png`
end

When I walk the tree, it makes the .dot files (with the draw frame method, I'm eventually going to make a .gif out of the files). Here, the call to dot... with backticks should make the png's, but it doesn't. If I run the exact same code in the command line, though, it works fine. Any ideas?

Upvotes: 1

Views: 192

Answers (2)

Confusion
Confusion

Reputation: 16841

You may want to consider using the ruby-graphviz gem.

Upvotes: 1

user1201210
user1201210

Reputation: 3809

Try the following instead:

`dot -Tpng #{@filename}#{x}.dot -o#{x}.png`

This replaces the stdout piping command > with a plain argument to dot telling it to write the file itself.

Upvotes: 0

Related Questions