File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes problems with using Runtime.getRuntime().exec().... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "problems with using Runtime.getRuntime().exec()...." Watch "problems with using Runtime.getRuntime().exec()...." New topic

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

vikram solanki

Joined: Dec 07, 2010
Posts: 12
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

Joined: Aug 16, 2005
Posts: 15083

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
vikram solanki

Joined: Dec 07, 2010
Posts: 12
Thanks a lot... that soled my problem...
Rob Spoor

Joined: Oct 27, 2005
Posts: 20273

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.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: problems with using Runtime.getRuntime().exec()....
It's not a secret anymore!