This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problems with using Runtime.getRuntime().exec()....

 
vikram solanki
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone... i am new to coding and i am having a bit of problem trying to execute a particular command...
i am trying to use Runtime.getRuntime().exec() to execute an .exe in command prompt... As output i am supposed to get an image(svg) file which is saved in a given directory... the code i am using for this is as given below...


i am using dot.exe to create the svg file... the poblem now is the SVG file is created but the size of the file is 0KB... but if i debug the prog everything is allright and i am getting an output file of some KB... can someone tell me the problem here please...
And i am using Netbeans6.7.1...
thanks a lot...
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch. Please UseCodeTags when you post source code (I added them to your post this time).

Try calling output.flush(); before you close the output stream (between lines 12 and 13). This will write the buffer to the file.
 
vikram solanki
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot... that soled my problem...
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you call Runtime.getRuntime().exec(...) this does not block the current thread. This means that the newly created process and the JVM are running concurrently. The deleting of the file on line 15 will probably occur before the launched process has finished. Use process.waitFor() to prevent this, but not before reading this article.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic