This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 14074
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
vikram solanki
Greenhorn

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

Joined: Oct 27, 2005
Posts: 19655
    
  18

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
 
jQuery in Action, 2nd edition
 
subject: problems with using Runtime.getRuntime().exec()....
 
Similar Threads
Runtime.exec
Inserting BLOB data
waitFor method of a process object not working
Response Ok, but message not delivered. (SMS)
Cant get the output of a class file through the following JSP