0

I am working on a project that requires drawing graphs from .dot files through Graphviz.

I have downloaded the Java API from the Graphviz site (http://www.loria.fr/~szathmar/off/projects/java/GraphVizAPI/index.php), but it doesn't seem to work. I changed the code a bit, specifically changing the variable that holds the location of the temp file to hold System.getProperty("java.io.tmpdir"), and I changed the variable that holds the location of the dot exe file to the location of the file on my computer.

When I run my code, the program stops showing progress (yet does not terminate), and running it in debug shows that is "stops" because it is waiting for the end of the exec command that draws the graph from the dot file.

What problem could there be that stops my code from running?

The code I'm running is basically the same as the example code in the comments at the start of the API file, with the onlt difference being that I'm loading a premade dot file and not creating a new dot source.

Wolf
  • 3
  • 1
  • (Not tested this yet, just curious) : What happens when you manually execute the command line that is passed (as `args`) to the `rt.exec(args)` call that is made in this program? Does this work in general? – Marco13 Jun 07 '14 at 12:25
  • How do you manually execute it? I'm using Windows, so would I run it through cmd? – Wolf Jun 07 '14 at 13:03
  • I tried running from cmd, and it isn't letting it run, but the error is that it doesn't recognize C:/Program as a command (the dot exe was in Program Files). It seems that placing spaces in the names of the folders where the dot exe, the source file and the destination image file were made the process fail to run. Moving things to places where there were no spaces made it run successfully, so I will try to do the same in my actual code and see if that works. – Wolf Jun 07 '14 at 13:34
  • Well, that's a first important insight, at least. You could move things to folders whose names do not contain spaces, or, alternatively, try to enclose the paths into `"` quotation marks. This could then be something like `private static String DOT = "\"c:/Program Files/Graphviz2.26.3/bin/dot.exe\""` (note that the quotation marks have to be *escaped* as `\"` !). Not 100% sure whether the latter will work, but it should... – Marco13 Jun 07 '14 at 14:02
  • @Marco13 Thanks for the help so far, I have tried moving the files to a directory without spaces (with the addition of the quotation marks in my code as a precaution), and the code I'm running as a test produces an empty file.Here is the code: `File file=new File("test.png"); gv.writeGraphToFile(gv.getGraph("Path of dot file here", "png"),file);`, where gv is my Graphviz object – Wolf Jun 09 '14 at 10:51
  • Well, it's hard to guess why *that* could be the case now. (This GraphViz.java is not very well structured - some exceptions seem to be swallowed, and the streams of the process are not read, so you don't see any error messages...). I wrote a snippet showing how to print the error messages in http://stackoverflow.com/a/21904185/3182664 , but am not sure whether you want to modify the GraphViz that far. Have you tried adding some log output, or ran it in a debugger? BTW: Does "empty file" mean "a file with 0 bytes", or "a file that is all black"? – Marco13 Jun 09 '14 at 12:56
  • @Marco13 empty file meaning 0 bytes. I ran it in debug earlier and saw that at the end of `get_img_stream`, meaning after the exec call, the termination of the thread where the dot exe was activated, and after the actual code resumed, the variable img_stream (which is returned at the end of the function) was an empty array. It seems to me that this shouldn't be happening, and that it might be better to attempt to just use the `exec` function from `Runnable` on its own in my code instead of messing about with this (I don't rely on this code for anything but drawing). Should I try this? – Wolf Jun 09 '14 at 14:55
  • Sorry, I'm not familiar enough with GraphViz etc. to give really profound hints here. However, does it create this temprorary file called `img`? In the end, it's not doing anything except for *reading* this file into a byte array (which, as you said, then had length 0...) – Marco13 Jun 09 '14 at 17:53
  • @Marco13 I can't check if it does make the file right now, but how would I check it? Also, I set the TEMP_DiR variable as `System.getProperty("java.io.tmpdir")`, shouldn't this make it so the temp file is made in the temp dir defined (and allowed) by the system? I would assume that there would be no problem making a file there, but what could stop the file from being made? Or did I not understand the getProperty function? – Wolf Jun 09 '14 at 19:29
  • Again: Sorry, I can't give specific hints. All I can do is making some more or less educated guesses, and give recommendations like that you should run it in a debugger, observe the output and variables and try to follow what it does. – Marco13 Jun 09 '14 at 22:48

0 Answers0