File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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

vikram solanki
Greenhorn

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: 14435
    
  23

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
Greenhorn

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

Joined: Oct 27, 2005
Posts: 19790
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problems with using Runtime.getRuntime().exec()....